Navigation menu

16 January 2016

Lesson #01: Intro to Object Oriented programming

Object oriented programming is a concept of treating everything as an object which has some properties and behaviors.

What are Objects?

An object is the working prototype of a class.

What is class?

A class is like a generalized blue-print of any object. It contains properties and abilities/behaviors of any object.

Example:


Let’s talk about cars. Toyota Camry and Audi r8. They are two awesome cars BUT how are they related to object oriented programming? Well, both Toyota Camry and Audi r8 are objects.

They are working prototype of some class, and what is that some class? Well, you guessed it! ‘Car’ is that class. A ‘Car’ here is a generic definition or blue-print of both car objects. This class has some properties and some behaviors.



Properties: body-color, model number, wheel-size, price, etc.
Behaviors: start, stop, accelerate and turn and so on.

So, object oriented programming is a structure or model by which you can treat everything as an object which will have some properties and some behaviors

Example #2:


A class of fruit can have many implementations. It may have properties like color, taste, seeds, minerals, etc



An apple is an object of fruit class. Notice that, apple is an object and it changes the default values of fruit class to something that will make that fruit object an apple. Here apple is changing default value of color to red, and leaf color to green. For the case of banana, some properties from fruit class but different values which makes it different from an object of apple.

No comments:

Post a Comment