Shutdown
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Object Orientation...

Go down

Object Orientation... Empty Object Orientation...

Post  lester.noronha Thu May 22, 2008 12:20 pm

For many of us programmers, it is tough to get into object oreinted programming from structural/procedural programming. Let us use this thread to discuss the very basic concepts of OO.


Last edited by lester.noronha on Thu May 22, 2008 12:38 pm; edited 1 time in total
lester.noronha
lester.noronha
VIP Member
VIP Member

Number of posts : 54
Registration date : 2008-04-29

Back to top Go down

Object Orientation... Empty Re: Object Orientation...

Post  lester.noronha Thu May 22, 2008 12:37 pm

One of the very basic concepts in OO is object orientation. I had a lot of issues getting this concept into my head. In the real world we can think of entities as classes/objects that have certain properties and can do certain actions.

For Example: Consider a human being like me. I have properties(data) such as my skin color, my heartbeat, my brain, etc. I have actions(methods) that I can perform such as run(), think(), eat(), etc. These so called methods perform changes to the properties. When I run(), my heart beat increases and when I think() my brain performs something(some people I know would override my think() method and print out "Method cannot be performed on specified object"). So we have a class, something like the following:-

class HumanBeing {
private String _skinColor;
private int _heartBeat;

HumanBeing() {
// initialize heart beat to 70
}

public String getSkinColor {
return _skinColor;
}

public void setSkinColor(String colorOfSkin) {
_skinColor = colorOfSkin;
}

void public run() {
// set heart beat greater than 80 depending
// on conditions
}
}

Forgive me for the syntax errors. One more point I forgot to mention here is the getter/setter methods. Always use these if you have to change or get the current property of the object. In other words only allow the methods to perform on the object data and do not allow direct manipulation of data from outside the class. This is partly data abstraction and encapsulation. You are hiding/encapsulating the data.
lester.noronha
lester.noronha
VIP Member
VIP Member

Number of posts : 54
Registration date : 2008-04-29

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum