I often hear....
the OO programming is object and message pass between them.
please give a simple example.
where is message. Is it a string?
The "message" is the method call.
e.g.
An instance of ClassA would send a message to objectB
ClassA::DoSomething()
{
objectB->SomeMethod();
}
Direct invocation is most common, but once you have this seperation you can move the objects between processes or computers and use IPC and/or networking to "send the message". See DCOM, CCM3, or .Net Remoting (not sure what it's called in Java).
e.g.
An instance of ClassA would send a message to objectB
ClassA::DoSomething()
{
objectB->SomeMethod();
}
Direct invocation is most common, but once you have this seperation you can move the objects between processes or computers and use IPC and/or networking to "send the message". See DCOM, CCM3, or .Net Remoting (not sure what it's called in Java).
I hate to say it, but I would probably either get a book on the subject of OOP (Object Oriented Programming) or take a class.
The basis of Object Oriented Programming is that an Object (or class) contains data and methods to access/modify the data in the class. Objects talk to each other by passing data/messages to each other. The kind of data/message being passed is really dependant on the specific situation.
Lets suppose I have two objects, a Lightbulb and Switch. They are somewhat like the following:
Lightbulb:
----------
State: On or Off
----------
+SetState(State)
Switch
---------
SwitchState: Up or Down
---------
+TurnOnLight(LightBulb)
+TurnOffLight(LightBulb)
Now, when I want to turn on the light, I would do something like:
Switch.TurnOnLight(DeskLamp)
The code behind this would be something like:
Switch::TurnOnLight(LightBulb)
{
LightBulb.SetState(On)
}
The Switch object basically sends a message to the LightBulb object, to tell it to change it's state from Off to On. I really would recommend getting a book on the subject, or even browsing a basic C++/Java/Object Oriented Programming book to get a rough idea of how things work.
The basis of Object Oriented Programming is that an Object (or class) contains data and methods to access/modify the data in the class. Objects talk to each other by passing data/messages to each other. The kind of data/message being passed is really dependant on the specific situation.
Lets suppose I have two objects, a Lightbulb and Switch. They are somewhat like the following:
Lightbulb:
----------
State: On or Off
----------
+SetState(State)
Switch
---------
SwitchState: Up or Down
---------
+TurnOnLight(LightBulb)
+TurnOffLight(LightBulb)
Now, when I want to turn on the light, I would do something like:
Switch.TurnOnLight(DeskLamp)
The code behind this would be something like:
Switch::TurnOnLight(LightBulb)
{
LightBulb.SetState(On)
}
The Switch object basically sends a message to the LightBulb object, to tell it to change it's state from Off to On. I really would recommend getting a book on the subject, or even browsing a basic C++/Java/Object Oriented Programming book to get a rough idea of how things work.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement