26-05-2012, 02:12 PM
Basic Object-Oriented Concepts
Basic Object-Oriented Concepts.ppt (Size: 108.5 KB / Downloads: 195)
Concept: An object has state
An object contains both data and methods that manipulate that data
The data represent the state of the object
Data can also describe the relationships between this object and other objects
Example: A CheckingAccount might have
A balance (the internal state of the account)
An owner (some object representing a person)
Example: A “Rabbit” object
You could (in a game, for example) create an object representing a rabbit
It would have data:
How hungry it is
How frightened it is
Where it is
And methods:
eat, hide, run, dig
Concept: Classes describe objects
Every object belongs to (is an instance of) a class
An object may have fields, or variables
The class describes those fields
An object may have methods
The class describes those methods
A class is like a template, or cookie cutter
You use the class’s constructor to make objects
Concept: Classes form a hierarchy
Classes are arranged in a treelike structure called a hierarchy
The class at the root is named Object
Every class, except Object, has a superclass
A class may have several ancestors, up to Object
When you define a class, you specify its superclass
If you don’t specify a superclass, Object is assumed
Every class may have one or more subclasses