Sunday 1 March 2015

OOP

Seeing as the topic I've talked about in my Slogs for the past couple of weeks has been recursion, I thought for this week's specified topic I'd shift tracks to OOP(Object Oriented Programming). As I think I may have mentioned in one of my earlier posts, OOP is the basic concept for most programming languages. For the two that I know so far, Python and Java, it is definitely something that forms the core of how these languages function.
In Object Oriented Programming, as the name suggests, everything is essentially an object. Whether it be a variable or a method or a class; they are all treated as objects, similar to how we use objects in the real world. These objects then interact with one another through the code to form an overall main structure or to maybe even form another object. The idea of OOP includes an object being an Abstract Data Type(ADT) and also having the property of inheritance, two concepts that we have studied in this course. Abstract data types that we have learnt about such as Stacks, Binary Trees, and Binary Search Trees are all objects themselves i.e. every stack is an object as is every Tree. Objects then also have hierarchies which means that inheritance enables one object to obtain the properties and functions of a parent class(as we have seen in our assignments with there being specific game states and strategies that inherit from the basic parent game state and strategy). Furthermore, OOP involves keeping the code and the inner workings of an object separate from its user interface. That is the whole purpose of having methods in classes that allow certain functions to be accessed through them while keeping the 'how' of the working separate.
All the programming we have done so far in the course has been object oriented. Something that I have noted is that what people tend to do when they first learn coding is to put all their code in one place, that is in the main program. This way of not using classes or methods does not utilize the full power of OOP. The code ends up being all over the place when it could have been put together and organized in methods and classes. Moreover, this prevents reusing code for say, recursion, or even more simpler things. Were we to do any of our assignments in just one single main program, the resulting code would be horrifically disorganized and very difficult to understand even to the person who coded it. Hence the advantages of OOP, unlike recursion, might not be that visible or that fascinating, but they still have great power in coding which needs to be understood and used properly. 

No comments:

Post a Comment