Disclaimer: I'm lame, I know.
Anyway, on to the topic. This week we're summarizing what we know about Object-Oriented Programming (OOP) concepts. First of all, OOP is a programming language model organized around objects rather than "actions" and data rather than logic. (Definition from here). For those who want to clarify what it is. Basically, the difference is that in logic, it takes an input, processes it and produces an output of data. The material we've mostly covered so far in CSC148 is all about OOP. Where we take objects and we want to manipulate them rather than the logic manipulating them. The object represents the state and behaviour.
So far under the OOP umbrella that we have learned, we learned the concepts of defining classes and subclasses, using inheritance...etc which are the basic concepts before you write any code. The key concepts that we covered thus far are:
- Class: which is an object that defines a set of attributes that characterize any object of the class
- Class statement is written as:
"""Class docstring
"""
#followed by methods your class wants to cover as well as __init__, __str__, __repr__... etc
- We also had some practice in creating instance objects, and accessing attributes in classes
- Inheritance: allows us to add extensions of existing classes to a new class which is the Subclass
- The subclass is the child class where as the existing class (as described above) is the parent class
- This is useful when you want to make a general class and apply it to different circumstances of that class. For example, if you want to make a general class Shape and make subclasses of specific shapes such as Square, Rectangle ..etc. This could be done by using inheritance and/or over-riding methods in the class itself.
- Inheritance in subclasses look like this:
""" Subclass doctstring, don't forget to mention that
it is inherited"""
def __init__(self, attribute, attribute):
"""
"""
ClassName.__init__(self, attribute, attribute)
#and assign anything else you need in this
subclass that is not in the superclass
I think these are the two main concepts of Object Oriented Programming that we have covered so far. We've worked with a lot of problem solving involving these concepts and had thorough practice in them. Also, I think going over the assignment and doing all the labs were a great practice in understanding these concepts! Also, this website has helped clarify any confusion I had with OOP and also looking back at the Proff's slides and hope this will help you as well. (Link here!) Cheers!
Edit: Here is a continuation of this post if you want to see these concepts come into play in problems that we've encountered in class to get a better grasp of these definitions and ideas. (Link to Examples Here!)
informative post!
ReplyDeleteI like your insight on OOP, and thank you for the links!
ReplyDeleteGreat summary! :)
ReplyDelete