Sunday, February 15, 2015

Summary on object oriented programming

After learning about object oriented programming for the past a few weeks, I acquired many skills in designing my own class objects and creating methods for them. Writing my own classes can allow me to create objects that Python does not provide and evaluate them in the way that I want it to work. Although in the beginning it was confusing for me because I do not really know what ‘self’ refers to. I tracked a lot of the example code in the lectures slide into Python visualizer and learned that ‘self’ refers to the class object that I’m creating, whenever I call ‘self.xxx’, Python knows to access the object with the appropriate instance variable, or the appropriate method of that class.

I think object oriented programming allows me to solve problems in a much more efficient manner. Inheritance, for example, can save me a lot of time in writing programs. With inheritance, I can now create objects that use features from another class that I have already written. This is very useful, because for example, I can create a superclass for my general courses, with features like returning course weight, grade achieved etc. With that, I can then create subclasses for my individual courses, without rewriting the same code, if I want to access the weight and grade for the specific course. Thus, object oriented programming extends the types of objects that Python currently provides, which make it handy and applicable to many different situations that a programmer may need.

Also, with enabling classes and instance variables, any client can create the object of the classes and use the methods written for them, without needing to know how the code achieves what it does. Just like I do not know what the code is for Python’s existing methods on its objects, like lists or dictionaries. But all I care is that I can use the append method to add items to lists, and the del method to delete keys in dictionaries. With classes, I can create my own objects for clients to use, with proper docstring provided to show what the methods do and others can write methods on objects that I may need to use. For example, a stack or a queue has very simple but useful features. Although I’m not the one who designed them, I can use their features and solve problems of my own need.


Learning object oriented programming had combined successes and failures. During the process, there were lots of confusion, especially when designing my own classes. I’m sometimes unable to come up with the appropriate instance variables a particular class should have, and the general methods that every subclass might share. However, it is undeniable that object oriented programming is efficient and useful. I hope to continue improve in the future.

No comments:

Post a Comment