I'm still quite curious about how function methods can talk to each other within different classes, I've been wondering about that for quite a while. |
First up, you need to double-check your terminology.
Function and
method are two different words used for the same thing; "function methods" is meaningless. I presume you meant "class methods" or "class functions".
It might be easier if you think of it as how do
classes talk to each other. That, after all, is the whole point of OOP - to make it easier for you, the programmer, to think about how to solve the problem, by letting you think in terms of objects, and easier to code the solution, by letting you create objects that mirror the solution inside your head. It's all to make it easier for you to think and code. When using objects makes things harder, it's become pointless.
Here's a simple example of an object of one class calling functions in a different class; a display class that is used to show a user information about people, where each person object is an instance of the personClass type.
1 2 3 4 5 6
|
personClass somePerson;
displayClass someDisplay;
// Lots of code setting things up, reading data etc etc.
someDisplay.showInfoAboutAPerson(somePerson);
|
So how does this object, someDisplay, which is of type displayClass, actually talk to the object somePerson (which is of type personClass)? By calling one of somePerson's functions - perhaps like this:
1 2 3 4 5 6 7 8 9
|
displayClass::showInfoAboutAPerson ( personClass thePerson)
{
// How does the display get data about the person to display it?
// Simple; the person object has functions that give back data about itself
int ageToDisplay = thePerson.ageOfPerson();
int heightToDisplay = thePerson.heightOfPerson();
// Code to actually do something with the data
}
|