Objects
Why have Objects??
-
To hide the implementation of on part of the program from other parts
-
Allows you to easily use someone elses code
-
Allows you to update part of a program with only limited changes to other
parts
-
Abstract Data Types
-
An ADT performs some function without displaying an implementation
-
Example: Is the dictionary a linked list, a binary tree, or a hash
table.
Vocabulary of Objects
-
Object -- A structure with methods
-
Method -- A procedure with an implicit argument
-
Class -- The type declaration of an object.
-
Instance -- A single object.
-
Inheritence -- Deriving a more specalized class from a less specialized
class.
What are Objects
Objects are a collection of procedures combined with a collection
of methods. Objects have
-
public specification -- a contract promissing what the function will do
-
public methods -- code that fulfills the contract
-
private methods -- code that helps the public methods
-
data -- any state information needed to store that data.
Data Protection
-
Public means anyone can see it -- performance for saftey
-
Private means no one can see it -- saftey for performance (accessor functions
to access)
-
Protected means derived classes can see it
-
but anyone can derive from you in C++
-
No one can derive from a 'final' class in Java.
Heirarchy
Inheritence is the deriving of more specalized classes from
more general classes.
You can add new class variables, new methods, and override old methods.
You can inheret from more than one class in some langauges (C++), sort
of do it in other languages (Java), and not do it in yet other languages.