Wednesday, January 7, 2015

Object Oriented programming

Module is a collection of classes,
Class is a definition,
and Object is a collection of data.

The object is actually an instance of class, it is 'born' based on the definition of the class. While module is a collection of classes.

This is for biology lover:

We have Kingdom, Family , Genus .....( I forgotten what I had memorized during high school)..
what makes those Families under that Kingdom is due to they have some similarities, but each of them is different.

For example, human and chimpanzee are under Hominidae, both is warm blood , about similar structure. In programming, human and chimpanzee inherit the definition in the Hominidae. Let's imagine them as each individual class. Human can walk, Chimpanzee can walk, Human extend from the base class and have something they have but Chimpanzee doesn't has.
in code:  class Human(Hominidae)
Human us a derive class and Hominidae is a base class.

In the human class, we have each individual human , just like U and I. We are an object , that is an instance of the human. We represent the human. ( object is a collection of data based on class)

Now, move a level up, before Hominidae, we have a super family which can act as module. Module is a collection of classes.

I had the idea after this interesting video that describe OOP with the city planner example. Here is the link.: https://www.youtube.com/watch?v=P1WcKEgvRFE

Usually, this concept is widely practice when a programmer do programming, but one mey notknow how to explain it. I normally will have a class contain all related functions. It is more manageable and cleaner in this way. For each function, try to let it only have a "mission" to archive.
Programming is an art. :)

No comments:

Post a Comment