Advanced Object Modeling
Advanced Object Modeling
Analysis and
Design
4 ADVANCED OBJECT
MODELING
Source: OBJECT-ORIENTED
MODELING A N D DESIGN
James Rumbaugh, Michael Blaha,
William Premerlani, Frederick Eddy,
William Lorensen
✘If the two objects are usually considered as independent, even though they may
often be linked, it is an association.
❤ Are some attributes values propagated from the whole to all or some parts?
Works for
Person
Aggregation
and
association
AGGREGATION versus GENERALIZATION
Fluorescent Incendescent
Base Cover Switch Wiring
Lamp Lamp
Twist
Ballast Starter Socket
mount
Aggregation
and
generalization
✘ Aggregation is sometimes called an and-relationship
and generalization an or-relationship.
✘ A lamp is made of a base and a cover and a switch and wiring and so on.
✘A variable aggregate has a finite number of levels, but the number of parts may
vary.
Program
Recursive
Block
Aggregate
Compound Simple
statement statement
PROPAGATION OF OPERATIONS
Propagation (also called triggering) is the automatic application of an operation to
a network of objects when the operation is applied to some starting object. For
example, moving an aggregate moves its parts; the move operation propagates to
the parts. Propagation of operations to parts is often a good indicator of
aggregation.
- A concrete class is a class that is instantiable; that is, it can have direct
instances.
-A concrete class may have abstract subclasses (but they in turn must have
concrete descendants).
-A concrete class may be a leaf class in the inheritance tree; only concrete classes
may be leaf classes insubclass
the inheritance tree.
subclass 1+ Class
1+
Has subclasses Object model
Has subclasses defining
abstract and
concrete class
Concrete Abstract
Instance
Has direct class class superclass
instances
Worker
Abstract class
and abstract
operation
Candlestick
Butcher Baker
Maker ...
Employee
year-to-date earnings
compute pay {abstract}
Concrete
classes
✘The origin class defines the protocol of the feature, that is the type of an attribute
or the number and type of arguments and result type for operations, as well as the
semantic intent. Descendent classes can refine the protocol by further restricting the
types or by overriding the initialization or method code. Descendent classes may
not expand or change the protocol.
✘A concrete class can usually be refined into several subclasses, making it abstract.
Conversely, an abstract class may become concrete in an application in which the
difference among its subclasses is unimportant.
3. GENERALIZATION AS EXTENSION A N D RESTRICTION
✘An instance of a class is an instance of all ancestors of the class. This is part of the
definition of generalization. Therefore all ancestor class features must apply to the
subclass instances.
✘Restriction implies that a subclass may not inherit all the operations of its
ancestors. Thus, the Circle class must suppress the unequal scale operation. On the
other hand, an object declared to be an ellipse is not restricted to remain a circle
even if its major and minor axes happen to be temporarily equal.
y
x
OVERRIDING OPERATIONS
❤ All query operations (operations that read, but do not change, attribute values)
are inherited by all subclasses.
❤ All update operations (operations that change attributes values) are inherited
across all extensions.
❤ Operations may not be overridden to make them behave differently (in their
externally-visible manifestations) from inherited operations. All methods that
implement an operation must have the same protocol.
✘Multiple inheritance permits a class to have more than one superclass and to
inherit features from all parents. This permits mixing of information from two or
more sources.
✘It brings object modeling closer to the way people think. The disadvantage is a
loss of conceptual and implementation simplicity.
DEFINITION
Multiple
inheritance
overlapping
LandVehicle WaterVehicle from
overlapping
subclasses
classes
disjoint
Car AmphibiousVehicle Boat
subclasses
join class
Multiple
Vested
inheritance
Hourly join class from disjoint
Employee
classes
A class can multiply inherit from distinct generalization or from different classes
within an overlapping generalization but never from two classes in the same disjoint
generalization.
University
Person
Member
Workaround for
accidental Faculty Student Staff
multiple
inheritance
Instructor
WORKAROUNDS
Dealing with lack of multiple inheritance is really an implentation issue, but early
restructuring of model is often the easiest way to work around its absence.
✘ Nested generalization
Factor on one generalization first, then the other. This approach multiplies out all
possible combinations. This preserves inheritance but duplicates declarations
and code and violates the spirit of object-oriented programming.
Employee
Employee Employee
Payroll Pension
Multiple
inheritance
using figure 1
delegation
Employee
Employee
Pension
Multiple
inheritance using
figure 2
inheritance and
delegation
Employee
pay status
Multiple
inheritance
figure 3
using nested
generalization
Any of these workarounds can be made to work, but all compromise logical
structure and maintainability. Some issues to consider when selecting the best
workaround are:
❤ If one superclass clearly dominates and the others are less important,
implementing multiple inheritance via single inheritance and delegation may
be best (figure 2).
❤ If one superclass has significantly more features than the other superclasses or
one superclass clearly is the performance bottleneck, preserve inheritance
through this path (figure 2 or figure 3).
❤ If you choose to use nested generalization (figure 3), factor on the most
important criterion first, the next most important second, and so forth.
Thus a data table may store the fact that the capital of Japan is Tokyo.
A metatable would store the fact that a country has a capital city.
PATTERNS A N D METADATA
(Person)
A class describes a set of object
instances of a given form. Joe Smith
Instantiation relates a class to its age = 39
Person weight =
instances. In a broader sense, name Notation for
158
any pattern describes examples age (Person)
of the pattern; the relationship weight instantiation
between pattern and example Mary Wilson
can be regarded as an extension age = 27
of instantiation. weight =
121
Real-world things may be metadata.
pattern object
CarModel Car
It is better to consider the model serial #
CarModel object as a year color
pattern, a piece of metadata, base price options
that describe Car objects.
Manufacturer Owner
Company Person
Pattern and
individuals
CLASS DESCRIPTORS
Classes can also be considered as objects, but they are meta-objects and not real-
world objects. Class descriptor objects have features, and they in turn have their
own classes, which are called metaclasses.
A class or association may have one or more candidate keys, each of which may
have different combinations and numbers of attributes.
The object ID is always a candidate key for a class. One or more combinations of
related objects are candidate keys for associations.
Comparison of
multiplicity with
candidate keys
for binary
associations
Project Language
Person
Ternary
associations
C A D program Mary C
control Susan Ada
software Mike C
C + + compiler Bob assembler
CAD Mike C
program Mike assembler
C A D program
C A D program
We deduce the candidate key by considering all the possibilities.
Student University
Professor
Ternary
associations
Student+University may be a candidate key, since no links share the same values.
Student+Professor+University is not a candidate key, because it is not a
minimal set of attributes.
7. CONSTRAINTS
DEFINITION
Constraints are functional relationship between entities of an object model. The
term entity includes objects, classes, attributes, links, and associations. A constraint
restricts the values that entities can assume.
Examples include:
- a constraint between two things at the same time;
Constraints
- a constraint between properties of a single object; on objects
- constraint on the same object over time.
boss Window
Employee length Job
salary width priority
GENERAL CONSTRAINTS
Subset Member_of
constraint
Person {subset} Committee
between
associations Chair_of
DERIVED OBJECTS, LINKS, A N D ATTRIBUTES
attribute
✘ The derived value notation is optional.
Derived
object and offset offset NetOffset
association
{offset = assembly_machine.offset Offset
× part_assembly.offset}
Homomorphism
for a parts
catalog
mapping
Maps
Contains Contains
CatalogItem Item
mapping
r
A B
General
t u homomorphism
{u(b,d) ‹ t(b.r, d.s)}
C D
s
Homomorphisms are most likely to occur for complex applications that deal with
metadata. The homomorphism is essentially just an analogy: a special type of
relationship between relationships.