Friday, 13 February 2015

Week 6: My summary of Object-Oriented Programming concepts

          When I first started programming in high school, I was introduced to the concept of object-oriented programming (a.k.a. OOP). Initially, I had to memorize the definition of OOP in order to pass my computer science exams. However, I had never really understood what OOP means and what it does. Now that I entered university studying in the computer science major, I felt obligated to master all programming-related concepts. So, after doing some research on the internet, I have summarized three important Object-Oriented Programming concepts that programming beginners should become familiarized with.

          First of all, one cannot leave out the definition of object. Now, object means different things under different contexts, however in computer science, it has only one definition. A software object is a model of real world objects, and similarly, a software object also shares two important characteristics, which are: state(or properties) and behaviour. In OOP, objects are created for programming purposes, and their behaviour consists of a set of methods/functions that the certain object performs, whereas the state encompasses all the objects’ properties and their associated values. Interestingly, an object is referred to as the instance of a class. And this leads us to the second OOP concept.

          A class is a representation of a type of object. In other words, it is similar to a blueprint that records all the instructions required to create a specific type of object. It consists of three characteristics:  name, attributes and methods. Since each class is designed for different purposes and contains different attributes, a program that is built to run certain application involves the implementation of countless different objects. Here is an example of a simple class
called Tiger:

Name Of Class: Tiger
Attributes: claws, fangs, golden fur
Methods: eat , roar, run

In this example, the attributes or properties of Tiger are its claws, fangs and fur, while the methods that the class encompasses include eat, roar and run. Since an object is the instance of a class (which is a specific object built from a certain class),  a tiger named Tina is an object created under the class Tiger. And Tina inherits all the necessary attributes and methods from its parent Tiger. Again, this brings me to my next concept.

          The last concept involved around the idea of inheritance of a class, which is the ability of a new class, when created, to inherit all the attributes and methods from an existing class. The new class is called the subclass, whereas, the original class is referred to as the parent class (or super-class). Using my previous example, I can create a new object called FemaleTiger, which is a subclass of the parent class Tiger. Like Tiger, class FemaleTiger also has attributes: claws, fangs, golden fur. Similarly, FemaleTiger also extended all the methods from Tiger: eat, roar and run. Furthermore, an advantage of using OOP is that not only can the subclass inherit functions from its parent class, the subclass also has the ability to add new attributes and methods to itself by overriding existing ones. For instance, subclass FemaleTiger can add another attribute, female, to itself. Furthermore, FemaleTiger can also override the methods it extended from Tiger, and replace them with: drink, give birth, breastfeed, and sit. Hence, my new subclass FemaleTiger will end up looking like this:

Name Of Class: FemaleTiger
Attributes: claws, fangs, golden fur, female
Methods: drink, give birth, sit, breastfeed

Likewise, I can create other subclasses like MaleTiger and BabyTiger:

Name Of Class: MaleTiger
Attributes: claws, fangs, golden fur, Male
Methods: drink, hunt, mate

Name Of Class: BabyTiger
Attributes: claws, fangs, golden fur, tiny stature
Methods: drink, sleep, play


          Although there are more things to say about OOP, such as interface, package,  encapsulation, and polymorphism, the rest is not currently related to my study and their information goes beyond my present knowledge. Thus I will conclude my summary of the OOP and discuss its relation with my Assignment 1. In A1, I was asked to create a generic game state class and later write out a specific game state subclass designated to the game Subtract Square. Despite having understood the general concept of OOP, I failed to properly divide the attributes between the parent and its child class. In other words, I did not properly include certain attributes that are common to all the specific games into the general game state superclass. I also realized that my general game state class mixed some specific attributes from the game subtract square. Hence, I want to remind all the programmers that despite how elementary the concept of inheritance sounds, applying it to programming is no simple tasks. I would recommend everyone to start creating classes with a piece of scrap paper, where they can jot down some similarities between the subclasses, and then include them in the general class. 
   
          In conclusion, OOP has many advantages, such as the ability to provide a clear modular structure for programs. Also, OOP is good for defining abstract data types (such as stack) and it allows easy modification and maintain of existing code as new objects can be created in a efficient manner using inheritance. However, despite all the pros, there are some cons associated with the application of OOP, and they are the fact that the size of object-oriented program tend to be larger, hence the large size slows down the execution speed of programs. Fortunately, recent improvement in compilers mitigated the problem.




4 comments:

  1. Great understanding on oriented-object programming concept! Helps me understand the concept better!

    ReplyDelete
  2. Good summary. Thank you for your writing. I learned a lot from it :)

    ReplyDelete