Page 180 - DCAP308_OBJECT_ORIENTED_ANALYSIS_AND_DESIGN
P. 180
Object Oriented Analysis and Design
Notes Any operation may be defined on several different classes in a group but undefined
on the other classes. Define it on the common ancestor class and define it as no
operation on the values that do not care about it.
2. Abstracting Out Common Behavior: Reexamine the object model looking for commonality
between classes. New classes and operations are often added during design. If a set of
operations/attributes seems to be repeated in two classes, it is possible that the two
classes are specialized variations of the same thing. When common behavior has been
recognized, a common superclass can be created that implements the shared features,
specialized features in subclass. This transformation of the object model is called abstracting
out a common superclass/common behavior usually the superclass is abstract meaning
no direct instances. Sometimes a superclass is abstracted even when there is only one
subclass; here there is no need of sharing. Superclass may be reusable in future projects. It
is an addition to the class library. When a project is completed, the reusable classes should
be collected, documented and generalized so that they may be used in future projects.
Another advantage of abstract superclasses other than sharing and reuse is modularity.
Did u know? Abstract superclasses improve the extensibility of a software product and
helps in the configuration management of software maintenance and distribution.
3. Use Delegation to Share Implementation: Sometimes programmers use inheritance as an
implementation technique with no intention of guaranteeing the same behavior. Sometimes
an existing class implements some of the behavior that we want to provide in a newly
defined class, although in other respects the two classes are different. The designer may
inherit from the existing class to achieve part of the implementation of the new class. This
can lead to problems –unwanted behavior.
14.1.7 Design of Associations
During object design phase, we must formulate a strategy for implementing all associations in
the object model. We can either choose a global strategy for implementing all associations
uniformly, or a particular technique for each association.
Analyzing Association Traversal
Associations are inherently bidirectional. If association in your application is traversed in one
direction, their implementation can be simplified. The requirements on your application may
change; you may need to add a new operation later that needs to traverse the association in
reverse direction. For prototype work, use bidirectional association so that we can add new
behavior and expand/modify. In the case of optimization work, optimize some associations.
One-way association
If an association is only traversed in one direction it may be implemented as pointer.
If multiplicity is “many” then it is implemented as a set of pointers.
If the “many” is ordered, use list instead of set.
A qualified association with multiplicity one is implemented as a dictionary object (A
dictionary is a set of value pairs that maps selector values into target values).
Qualified association with multiplicity “many” are rare. (It is implemented as dictionary
set of objects).
174 LOVELY PROFESSIONAL UNIVERSITY