2. Object Oriented Modeling

Systems and Models

A model is an abstraction that represents a system. Scientists, engineers, and system analysts build models. Cognitive psychologists believe that model building is the basic skill underlying all other human cognitive abilities.

Examples of systems:

biological systems: whales, brains, redwood trees, etc.

physical systems: gallaxies, stars, planets, oceans, ecosystems, molecules, etc.

engineered systems: computers, computer programs, computer chips, steam boats, coke machines, nuclear reactors, cars, etc.

enterprises: armies, governments, corporations, universities, assembly lines, etc.

Examples of Models

model = function

A functional model models the input-output behavior of a system.

Functions are built from simpler functions using composition

functional models can be drawn using data flow diagrams

calculus, LISP, and behavioral psychology are good examples of this type of modeling.


model = relation

Relations satisfy axioms and rules.

Sibling(A, B) & Sibling(B, C) => Sibling(A, C)
Sibling(A, B) => Sibling(B, A)
not Sibling(A, A)

Logic (relational calculus), AI, Prolog, relational dbase, and SQL are good examples of this type of modeling.

model = computer

Also called the imperative paradigm. Before computer languages supported declarative (functional and relational) or object-oriented paradigms, we needed to implement our models in a language that reflected rather than disguised the underlying structure of the computer. This task was made easier if the model "looked" like a computer to begin with. In essence, the model needed to have an internal state (memory) that was perpetually updated by a control loop (the processor) until a final state was reached (termination).

Actually, the computer model isn't a bad fit for most discrete dynamical systems. We will visit it again when we introduce active objects.

model = object

An object is a physical entity that has mass and volume. Toasters, motor boats, planets, and balony sandwiches are examples of objects. Objects have lifecycles. They are created, manipulated, saved, restored, and destroyed. Objects can have internal states and external behavior. Objects are less abstract than relations and functions. Objects are the first things we perceive in the world around us.

Object-oriented modeling means treating concepts and abstractions as physical objects. We might call this "objectification". Examples of possible objects include:

functions, relations, places, events, transactions, strategies, plans, views, algorithms, messages, connections, organizations, activities, mechanisms, inferences, theories, measurements, commands, types, etc.

Object-Oriented Concepts

Concept Map

1. An object has an internal state that occasionally changes. We say that an object encapsulates its state. This means access to the state is controlled. The state of an object can be identified with the properties or attributes of the object.

2. The state of an object can be thought of as a point in a state space. The state space describes the domain of all possible states.

Example: A particular type of vending machine is an object that sells three types of candy bars: Mars, Hershey, and Nestle. The machine can hold up to 50 of each type of candy bar. The state of a machine can be described by three numbers:

m = #Mars bars in stock
h = #Hersy bars in stock
n = #Nestle bars in stock

The state space of the machine can be described by the sentence:

m, h, and n are all integers between 0 and 50.

3. An object exhibits behavior. This behavior depends on the object's internal state and the object's environment. We can model an object's behavior as a collection of functions called methods. Alternatively, we can think of an object's methods as the services the object performs or as the means of controlling the object.

Example: We can't just grab the candy bars in our vending machine. We must put in the right amount of money in a slot and push the right button. These slots and buttons are the vending machine's methods.

4. Objects interact by invoking methods. In this context the invoker is called a client and the invokee is called a provider or server. A method may be invoked directly using a function call mechanism:

Alternatively, a message may be invoked indirectly using a message passing mechanism:

5. A class describes the state space and methods for an object. We say that the object instantiates the class. We separate the state space and methods into a class because many objects may share the same state space and methods, even though they have different states. For now we can identify a class with a data type.

Example: Our vending machine is a Deluxe 50, the top model produced by the Acme Vending Machine Co. All Deluxe 50 machines have the same capacity (state space) and controls (methods), but different machines will be in different states (i.e. have different numbers of candy bars in stock.) We can think of Acme Deluxe 50 as a vending machine class.

6. There are two ways clients can use a class. "End users" simply create instances of the class. "Value adders" enhance a class by adding additional features. Clients of value adders might be end users or value adders. The enhanced class is called a specialization or extension of the original class. The original class is called a generalization of the enhanced class. The specialization inherits the features of its generalization.

Example: Acme gets an order for 5000 Deluxe 50 class vending machines from VAR Corp. Surprisingly, no one at VAR even likes candy bars. That doesn't matter, because VAR isn't planning to install the machines. Instead, VAR adds a change making mechanism to each machine and slaps a new name tag on it: "VAR Super Deluxe 500". VAR then resells these machines to their client: the Diabetes ward of the county hospital. The VAR Super Deluxe 500 class specialzes the Acme Deluxe 50 class.

7. We need to attach names to objects. Sometimes we need to attach the same name to different objects at different times. A name can be attached to an object using a handle. Pointers, references, URLs, IP addresses, HWNDs, and ID numbers (OIDs) can all be examples of handles.

8. When a name is declared we must declare its type. A type is similar to a class, except it doesn't specify a state space, and it doesn't specify how the methods are implemented. Instead, it only specifies the signatures (a.k.a. headers, prototypes) of the methods. In some cases axioms describing the relationship between the inputs and outputs of the methods may also be specified. In this context a type is also called an abstract data type (ADT) or an interface. We can relax the definition of a type by allowing state spaces and partial or default implementations of functions. In this case we may think of the type as a polymorphic or abstract class.

9. Any class the implements methods that have the signatures specified by a type is said to implement the type. If class A implements type T, and class B specializes class A, then class B also implements type T.

10. A name can only be attached to an object if the class of the object implements the type of the name.