Let's summarize our discussion of objects and
classes:
Classes
-
A class is a template for a
group of objects.
-
A class is a definition with
common variables and methods.
-
Classes are hierarchical in
nature.
-
Classes can have subclasses.
-
Classes are sometimes
referred to as an object type.
Objects
-
An object is an instance of a
class.
-
Each object is given a unique
object identifier when it is created.
-
When an object is created it
?inherits? all data attributes from the class definition.
-
When a method is requested
against an object, it inherits all methods from it's class and its
superclasses.
-
Each object has it's own
private data storage area in memory.
-
Each object has public
interfaces.
In Object Technology the terms ?object? and
?class? are often used interchangeably. Sometimes the term object is used to
refer to a class and other times object is used to mean an instance of a class.
Remember, objects are an instance of a class but they also contain all of the
properties of the class that created them. A class is its own entity and so is
an object.
Messages
Messages are how programmers activate the
methods for an object. There are two distinct form for methods, the procedure
method and a function method. A procedure method never returns a value. But a
function method will always return a value. A message can tell an object to do
several things. A message will either update some of the objects data or
perform some calculation and return a value to the calling program. Generally
speaking, a parameter string is associated with the message, and this parameter
string includes all of the necessary information to tell the object what to do.
Here are some examples of message calls to database objects:
order_total = compute_order_total(123); /* This returns an
integer */
credit_status = check_customer_credit(?jones?); /* This
returns a Boolean */
Update_inventory_level(?widget?, 37373); /* This does not
return a value */
The message with the parameter string being sent
must match one of the objects interface types (methods) in order to perform the
requested operation. If the method cannot be found in the class hierarchy then
an error will occur.
Messages in OT are very similar to subroutine
calls in conventional programming languages. Conventional languages would have
one procedure call another procedure, which, in turn, may call other procedures,
and so on. For example, the calling procedure (sender) would ask another
procedure (receiver) for some information, the sender would send a parameter
string with the call and the receiver would send the requested information back
to the sender using the parameter string.
Abstract classes
An abstract class is a class that is never
instantiated. That is, an abstract class serves only to pass data structures
and methods to lower-level classes. An abstract class is a class that has no
objects, it is put in the class hierarchy mainly to just help organize the
structure. Subclasses of the abstract class can have objects.
An abstract class can serve a very useful
purpose with inheritance. When a class hierarchy is setup one of the things
assigned to each class are its behaviors and data structures. When each
subclass is used to create an object, the object inherits all of the data
structures associated with the abstract class. At runtime, abstract class are
used for the inheritance of methods.
Figure1-7 Abstract Class
Figure 1-7 shows
1. Show the data types within each object
executive. . . .
Hourly . . .
2. Illustrate inheritance
use compute_pay and user the term overload to
describe compute_pay() for the executive.
Elaborate on this example. . . . . .