Object-Orientated Programing
Object-Orientated Programing
I have been programing for years on my spare time. I have developed small games, servers and other programs which requires object-orientated programming. Most of my programming skills come from experience and looking at small tutorials/docs for minor things such as how to use a certain type of variables and its methods. I usually put effort into learning new things about a certain programming language rather than enhancing the skills I have right now. This results in knowing a lot about a certain language(i.e. knowing variables and what I can do with them) but having poor style and doing things the long, complicating way. This is my main reason of selecting this course, to improve my programming style and to learn new useful techniques and when to use them(i.e recursion).
Before taking this course, I barley understood what object orientated programing means. I just wrote codes, and did many OOP while not fully understanding whats happening. This would sometimes cause problem. For example, I used to be really confused and lost when I'm trying to use a particular instance of a class in a particular way but ended up creating a new class (the problem was much more complicated).
After taking this course, I have a deeper understand of OOP.
There are three main vocabularies to know when thinking about OOP.
Object: Similar to real life objects; They contain data (i.e. name, age) and functionality (i.e. walking, reading)
Class: A template or blueprint of objects which contains variables and methods
Instances: A unique copy of a class which refers to an object.
So for example:
Lets say you have 5 different phones. Each of these phones is an Object of type Phone.
When programming, you create a class called Phone, which has variables such as size, service provider and colour. It also has some methods to describe the behavior such as turn on, calling, sending. This class is a blueprint of the object Phone.
Since we have five phones, each of these phones is an instance of the Phone class, which represents the object.
Each of the instances will have different variables set (i.e. one phone is blue while the other is red). These instances can also call methods to perform a behavior (i.e. one phone can be sending a text, the other can be turning off, and the rest can be doing nothing).
Now that I have a deeper understanding of Object Orientated Programing, I want to talk about something new I learned from a tutorial. If I want to compare two instances, I'd normally have a function that takes in both instance and compare them. But apparently, this isn't a proper way of doing things. What I was told is that it's better to create a method inside the class and do the comparing there.
I personally still am confused on why this is more appropriate. When creating this method inside a class, we can call the method by the first instance or the second instance. For example:
a.compare(b) or b.compare(a)
I feel like I'd rather have: compare(a,b)
But this way also works and since it seems conventional, I gotta put my personal taste aside.
As mentioned earlier, I had very limited knowledge of what OOP is even though I have been using it for years. Fortunately, I feel as if I have achieved great understanding on OOP and I've gotten really confident with this topic. I'm looking forward to my next lecture and tutorial in this course.
Thanks, see you next week :)
