Wednesday, 1 April 2015

Object Oriented Programming Summary

Object Oriented Programming Summary

Superclasses
Superclasses (or sometimes called parent classes) are generic classes that very broad methods that may need to be implemented in a subclass (this is often the case). Superclasses act like an umbrella in that depending on what the superclass is, many subclasses could fall under the umbrella of the superclass. For example, if I were to create a program for organizing or creating poetry, the superclass would be a generalized Poetry superclass and its sublclasses would be the different types of poetry (eg, haiku, limerick, sonnet, etc).

Subclasses
Subclassas are more specific classes under a superclass. They have all the attributes of the superclass they are a part of but have more specific information and functions contained within it than the superclass. Going back to the poetry example, the superclass Poetry would have various methods which would not be able to be implemented because the superclass lacks information since it's too general. Let's take the example of having a method that checks the rhyme scheme of a the poetry type. The method cannot be implemented in the superclass since the rhyme scheme of different poetry types is different. However it can be implemented in the subclass where the rhyme scheme of that particular poetry type is defined.

Inheritance
Inhertence is an important element of OOP. It allows for information to be passed from a superclass to its subclasses. When a subclass is created, it will inherited all aspects of the superclass and will have access to all of its methods. When writing methods of the subclass that are present in the superclass, the variables and attributes that are defined need to be stated and if you don't want to inherit a variable, it must be intialized in the code of that method otherwise it will produce an error (learned from personal experience...). However, the number of parameters in the subclass must match the number in the superclass or else once again, an error will arise.

For me, understanding inheritence and how to write the code in a subclass and determining what was inheriteed and what wasn't was difficult. In some cases, there were subclasses where almost nothing in certain methods was inherited and in others, almost everything was inherited aside from a few specific elements. But in the process of playing around with superclasses and subclasses and from working on Assignment 1, I gradually got the hang of it.



2 comments:

  1. This was a really interesting post about object oriented programming, I gain some insight from your post. It is very detailed.

    ReplyDelete
  2. This was a really interesting post about object oriented programming, I gain some insight from your post. It is very detailed.

    ReplyDelete