Hi guys!
Object Oriented Programming (OOP) was a tough concept to
learn at first. It made no sense and seemed useless. However, the assignments
we’re given for the semester helped me see why OOP is useful. When we work on our
assignments, designing new games each time and creating a new subclass for each
game that is specific to the game while inheriting methods from a common parent
class makes life much easier than having to do things (i.e. designing functions
and attributes) separately and repeatedly for each game. So let’s explore the OOP
concepts we’ve learned so far this semester: objects, abstract data types, methods,
inheritance, and recursion.
Objects
Objects contain both information and behaviour. When
working with Python, every value is an object with a specific memory address whose
behaviour can be accessed using the dot (“.”) operator. So classes, subclasses,
methods, and arguments are all objects in Python.
ADTs
ADTs or Abstract Data Types are not specific to any particular
programming language which is why they’re so great. They specify what was meant
to be stored and particular operations provided on the data. Examples of ADTs we’ve used in class are stacks,
and queues. You can use stacks and queues in real life and in other programming
languages. They're not specific to Python which is why they're so useful.
Methods
Methods perform one of two major functions. They're functions that are attached to a class
instance and compute and report property related to that instance. Or they
change/mutate properties of the instance while using information from it to perform their operations. We also learned about special methods
that, in Python, are inherited from the object type but can be overridden when wanted. A few of these
methods are ‘__eq__’, ‘__str__’, ‘__repr__’, and ‘__init__'.
Inheritance
We also learned about inheritance in lectures.
Inheritance is when one or more subclasses inherit methods and attributes from
their parent class. These subclasses can then override and extend the methods initialized in the parent class to perform operations specific to their own
needs and operations.
Recursion
Recently we learned about recursion where a function
calls itself in its own body. We learned how to trace recursive functions and
predict outcomes of specific recursive functions by analyzing the code. We also learned how to prove
that a function carries out its task thoroughly for various depths of input (i.e. we proved that the function works for inputs of various depths).
That is a short summary of all the OOP concepts we’ve learned
so far in CSC148. With this I'd like to conclude this post and wish you all a great reading week!