Skip to content

Introductory OO concepts

July 8, 2011

This is a good overview.

This is another good overview 7 steps…

Another very good example of 4 pillars of OO – featuring C++ implementation (pillars =

(abstraction, inheritance, polymorphism, encapsulation)

Super good explanation of polymorphism in wikipedia implemented in a bunch of popular languages.

This is a  learning OO in Java “trail“.

Always use the existing plethora of media examples to explain things.  Try, OOP – type in Object Oriented Programming in youTube.

Most languages will also have a concept of constructor, destructor methods.  We know about all about the constructor method of a class and how it is automatically executed when an object is created from the class.  The destructor is run when the object is killed or deleted.  The primary use of the destructor is to free up memory or re-allocate memory for future objects.

As you explore the concepts of inheritance and polymorphism, you start to see the concept of interfaces.  The interface is a “contract” between the parent class and its derived children.  The interface of the class says that any class that is derived from it will have these methods available to it. The interface is alike a public API for the developer wanting to use a class.  The developer says, “that’s an interesting class, i wonder how i can use it?”  The developer looks at the interface for the class and sees the methods avail. to the class and what needs to be sent to the method for it to do its work.  The developer does not need to know how the method is doing its work, they only need to know what it needs.  Think of it like this;

I see a girl, i need to know how to talk to it, i see a method called smile, i would like to see it smile, so i look more closely at the method and it says tell me a joke, so i tell it a joke and it smiles.  I don’t need to know how the joke made it smile, I only need to know what to pass to it.  If i like the girl, i can look at other ways to communicate with her, via her interface.

Upon studying the girl further, you notice in her interface a method called laugh, only its not implemented, you try calling it, but she is quiet.  You realize now that different girls laugh different ways.  When you create new girl classes, deriving them from the original, you agree to define the laugh method.  Lets say you create 3 new specilized girl classes, each derived from the base or parent or super girl class.  Everything in the base class is copied into the new girl class, including the laugh method.  You decide to define what the laugh sounds like a little differently in each of your newly derived classes.  You could have little girl squeal laugh, teenager drama laugh and adult honest laugh.  The polymorphism concept happens when you create a view class that instantiates the parent class and calls the laugh method, the behavior is different.


From → Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: