Object Orientation...
Shutdown :: Technical Discussions :: Need Help! :: OOAD
Page 1 of 1
Object Orientation...
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- VIP Member
- Number of posts : 54
Registration date : 2008-04-29
Re: Object Orientation...
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.
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- VIP Member
- Number of posts : 54
Registration date : 2008-04-29
Shutdown :: Technical Discussions :: Need Help! :: OOAD
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|