2010-09-21, 01:21 PM
OOP is meant to follow natural language by letting code mimic the real world.
An object is any thing that you can dream up. Think of a notebook for example. A notebook is an object. An object is merely a thing with which you can perform actions on it. So you can read a notebook, write in the notebook, and update a notebook. These actions are of a "can" relationship with the notebook (you CAN read a notebook [Notebook.Read()], you CAN write in it [Notebook.Write()], you CAN update it [Notebook.Update()]). All "can" relationships are functions within the object.
Then you have "has a" relationships. So a notebook has a number of pages, it has a current page opened, it has a spiral binding, and it has a front cover. All of these "has a" relationships are variables within the object (int, short, string). In the struct shown above, each Score struct "has a" count and "has a" total.
The idea of OOP is data hiding. Ideally, the only way you should interact with an object is by sending commands to the object and never change its variables directly.
An object defines an abstract concept. For example, in the object definition you define what every notebook should look like. But the certain one on your table is one instance of that object. Every notebook you come across is a different instance of that object. Then you can change the state of each notebook by sending commands to its instance. Like in the real world, you can update the notebook on your desk without updating every single notebook in the universe.
Then you have "is a" relationships. This defines inheritance. So a diary is a kind of notebook. A daily planner is a kind of notebook. Inheritance specifies a more explicit type of your object. You can then inherit all of the functions from Notebook (read, write, update) into the diary object, but also include specific functions to make working with diaries easier (getCurrentDate(), WriteJournalEntry(), setCurrentMood())
If you still feel a bit lost, check out the Java introduction to OOP. Pretty much everything there will translate to any OOP language you encounter. The names might be slightly different, though.
EDIT: Nail down Objects ASAP. If you don't, you will be brutally destroyed by the time you start learning about OOP patterns.
An object is any thing that you can dream up. Think of a notebook for example. A notebook is an object. An object is merely a thing with which you can perform actions on it. So you can read a notebook, write in the notebook, and update a notebook. These actions are of a "can" relationship with the notebook (you CAN read a notebook [Notebook.Read()], you CAN write in it [Notebook.Write()], you CAN update it [Notebook.Update()]). All "can" relationships are functions within the object.
Then you have "has a" relationships. So a notebook has a number of pages, it has a current page opened, it has a spiral binding, and it has a front cover. All of these "has a" relationships are variables within the object (int, short, string). In the struct shown above, each Score struct "has a" count and "has a" total.
The idea of OOP is data hiding. Ideally, the only way you should interact with an object is by sending commands to the object and never change its variables directly.
An object defines an abstract concept. For example, in the object definition you define what every notebook should look like. But the certain one on your table is one instance of that object. Every notebook you come across is a different instance of that object. Then you can change the state of each notebook by sending commands to its instance. Like in the real world, you can update the notebook on your desk without updating every single notebook in the universe.
Then you have "is a" relationships. This defines inheritance. So a diary is a kind of notebook. A daily planner is a kind of notebook. Inheritance specifies a more explicit type of your object. You can then inherit all of the functions from Notebook (read, write, update) into the diary object, but also include specific functions to make working with diaries easier (getCurrentDate(), WriteJournalEntry(), setCurrentMood())
If you still feel a bit lost, check out the Java introduction to OOP. Pretty much everything there will translate to any OOP language you encounter. The names might be slightly different, though.
EDIT: Nail down Objects ASAP. If you don't, you will be brutally destroyed by the time you start learning about OOP patterns.
