Thursday, 19 February 2015

Week 6: Object Oriented Programming

What Is Object Oriented Programming:
Object Oriented Programming, or OOP, is a style of coding. In OOP, as the name suggests, a programmer deals with different objects that they define such as a dice or a card. The programmer decides what attributes these objects have and what these objects can do. A card for example could have different attributes depending on what game it is for. Each class also has methods which determine what the objects of that class can do.

Uses of OOP:
OOP is very useful since it can help save a lot of time when coding. A class can be thought of as a sort of recipe for making objects. Because of this, a programmer can keep referring to it when making objects instead of writing out each attribute for every individual object.

OOP is also a great way of organizing ideas. Without OOP, it would be more difficult to read and analyze code it would be less clear what is going on. With classes, a person can clearly see what each objects represents, what attributes they have, and what they can do.

This style of coding is also helpful in solving very large problems. OOP is thought of as bottom up programming since the programmer starts with the simplest objects then gets more and more broad. For example, you could have a class for a specific card, then a broader class would be a hand of cards, then an even broader class would be the the hands of cards for every player. This makes it easier to approach and code large programs.

Inheritance:
Inheritance is a way to broadly define what each object should have. Abstract classes defines what attributes or methods a subclass of this class must have. For example, one could have an abstract class for dices. In this abstract class one could define an attribute as a list of all the possible values the dice can have and a method where a random value is chosen. Then a class that inherits from this abstract class could be a class for a six-sided dice, or a class for a twenty-sided dice.

No comments:

Post a Comment