Block 3 MS 032 Unit 5
Block 3 MS 032 Unit 5
1.0 INTRODUCTION
In the previous Blocks of this Course we learned the differences between OOA and
OOAD and how UML is used for visualizing, specifying, constructing, and
documenting.
The goal of object design is to identify the object that the system contains, and the
interactions between them. The system implements the specification. The goals of
object-oriented design are:
(1) More closely to problem domain
(2) Incremental change easy
(3) Supports reuse. Objects during Object Oriented Analysis OOA focuses on
problem or in other word you can say semantic objects. In Object Oriented
Design we focuses on defining a solution. Object Oriented modeling is having
three phases object modeling, dynamic modeling, and function modeling. In
this Unit we will discuss the concepts of object modeling. We will also discuss
aggregation, multiple inheritance, generalisation in different form and metadata.
1.1 OBJECTIVES
After going through this unit, you should be able to:
• describe and apply the concept of generalisation;
• understand and apply the concepts abstract Class, multiple Inheritance;
• apply generalisation as an extension;
• apply generalisation as a Restriction, and
• explain the concept of Metadata and constraints.
In this whole process first of all we have to identify objects, then structures, attributes,
associations, and finally services.
1.2.1 Aggregation
Aggregation is a stronger form of association. It represents the has-a or part-of
relationship. An aggregation association depicts a complex object that is composed of
other objects. You may characterize a house in terms of its roof, floors, foundation,
walls, rooms, windows, and so on. A room may, in turn be, composed of walls,
ceiling, floor, windows, and doors, as represented in Figure 1.
In UML, a link is placed between the “whole “and “parts” classes, with a diamond
head (Figure1) attached to the whole class to indicate that this association is an
aggregation. Multiplicity can be specified at the end of the association for each of
the part-of classes to indicate the constituent parts. The process of decomposing a
complex object into its component objects can be extended until the desired level of
detail is reached.
House
Roofs Roofs
You can see that object aggregation helps us describe models of the real world that
are composed of other models, as well as those that are composed of still other
models. Analysts, at the time of describing a complex system of aggregates, need to
describe them in enough detail for the system at hand. In the case of a customer order
and services, a customer order is composed not only of header information, but also
the detail lines as well. The header and detail lines may each have public customer
comments and private customer service comments attached. In an order entry system,
detailed technical information about a product item appearing on a customer order line
may be accessible as well. This complex object-called an order can be very naturally
modeled using a series of aggregations. An order processing system can then be
constructed to model very closely the natural aggregations occurring in the real
world.
Aggregation is a concept that is used to express “part of” types of associations
between objects. An aggregate is, a conceptually, an extended object viewed as a
Unit by some operations, but it can actually be composed of multiple objects. One
aggregate may contain multiple whole-part structures, each viewable as a distinct
aggregate. Components may, or may not exist in their own right and they may, or may
6
not appear in multiple aggregates. Also an aggregate’s components may themselves Object Modeling
have their own components.
0..n 0..n
Person Company Division Department
Position
Total
Starting Date
Salary
Figure 2 shows that a person works for a company, company has many division,
which are part of company and each division has many departments, which are again
part of division.
1.2.2 Abstract Class
An abstract class is used to specify the required behaviors (operations, or method
in java) of a class without having to provide their actual implementations. In other
7
Modeling words you can say that methods without the implementation (body) are part of
abstract classes.
An abstract object class has no occurrences. Objects of abstract classes are not
created, but have child categories that contain the actual occurrences. A “concrete”
class has actual occurrences of objects. If a class has at least one abstract method, it
becomes, by definition, an abstract class, because it must have a subclass to override
the abstract method. An abstract class must be sub classed; you cannot instantiate it
directly.
Here you may ask one question: Why, are abstract classes are created? So the answer
to this question is:
• To organise many specific subclasses with a super class that has no concrete
use
• An abstract class can still have methods that are called by the subclasses. You
have to take is this correct point in consideration in case of abstract classes
• An abstract method must be overridden in a subclass; you cannot call it directly
• Only a concrete class can appear at the bottom of a class hierarchy.
Another valuable question to ask is: why create the abstract class method? Answer to
this question is:
• To contain functionality that will apply to many specific subclasses, but will
have no concrete meaning in the super class.
Shape
-orange
-color
+ move ()
+ resize ()
+draw ()
Figure 3: How abstract and concrete classes are related. Consider the example of shapes.
For example in Figure 3, you can see that the shape class is a natural super class for
triangle, circle, etc.
Every shape requires a draw () method. But the method has no meaning in the Shape
super class, so we make it abstract.
The subclasses provide the actual implementations of their draw methods since
Rectangle, Polygon and Circle can be drawn in different ways. A subclass can
override the implementation of an operation inherited from a super class by declaring
another implementation. In this example, the draw method of rectangle class overrides
the implementation of the draw operation inherited from the Shape class. The same
applies to draw methods of Polygon and Circle.
Abstract classes can appear in the real world and can be created by modelers in order
to promote reuse of data and procedures in systems. They are used to relate
concepts that are common to multiple classes. An abstract class can be used to model
an abstract super class in order to group classes that are associated with each other, or
8
are aggregated together. An abstract class can define methods to be inherited by Object Modeling
subclasses, or can define the procedures for an operation without defining a
corresponding method. The abstract operation defines the pattern or an operation,
which each concrete subclass must define in its implementation in their own way.
EMPLOYEE
Fname, Lname
Id
Pay ();
hire();
For example, in Figure 4, you can see that EMPLOYEE class is inherited from
PERSON class.
Multiple inheritance extends this concept to allow a class to have more than one parent
class, and to inherit features form all parents. Thus, information may be mixed from
multiple sources. It is a more complex kind of generalization; multiple inheritances
does not restrict a class hierarchy to a tree structure (as you will find in single
inheritance). Multiple inheritance provides greater modeling power for defining
classes and enhances opportunities for reuse. By using multiple inheritance object
models can more closely reflect the structure and function of the real world. The
disadvantage of such models is that they become more complicated to understand and
implement. See Figure 5 for an example of multiple inheritance. In this example, the
VAN classes has inherited properties from cargo Vehicle and Passenger vehicle.
Vehicle
The advantage of multiple inheritance is that it facilitates the re-use existing classes
much better than single inheritance. If the properties of two existing classes have to be
re-used and only single inheritance was available, then one of the two classes would
have to be changed to become a subclass of the other class.
However, multiple inheritance should be used rather carefully. As the inheritance
relationships that will be created through multiple inheritance may become rather
complex and fairly difficult to understand. It is seen as a controversial aspect of
object–orientation and, therefore, not implemented in some object-oriented languages,
such as Smalltalk, because sometimes multiple inheritance can lead to ambiguous
situations.
10
Object Modeling
You will observe that:
• Working with multiple inheritance can be difficult in implementation if only
single inheritance is supported, but analysis and design models can be
restructured to provide a usable model. Rumbaugh et al. discusses the use of
delegation as an implementation mechanism by which an object can forward an
operation to another object for execution. The recommended technique for
restructuring-includes:
Delegation using an aggregation of roles a super class with multiple
independent generalizations can be recast as an aggregate in which each
component replaces a generalization.
For this you have to:
• Inherit the most important class and delegate the rest. Here a join class is made
a subclass of its most important super class.
• Nested generalization: factor on one generalization first, then the other,
multiplying out all possible combinations.
Rumbaugh suggests issues to consider when selecting the best work around:
• If subclass has several super classes, all of equal importance, it may be best to
use delegation, and preserve symmetry in the model
• If one super class clearly dominates and the others are less important,
implementing multiple inheritance via single inheritance and delegation may be
best
• If the number of combinations is small, consider nested generalization
otherwise, avoid it
• If one super class has significantly more features than the other super classes, or
one super class is clearly the performance bottleneck, preserve inheritance
through this path
• If nested generalization is chosen, factor in the most important criterion first,
then the next most important, etc.
• Try to avoid nested generalization if large quantities of code must be duplicated
• Consider the importance of maintaining strict identity (only nested
generalization preserves this). Now, let us discuss the concept and
specialization of generalization which is very important in respect of object
oriented modeling.
Employee
Salaried Hourly
Worker Worker
Manager Non-Manager
12
Object Modeling
• Update operations that change constrained attributes or associations are blocked
across a restriction.
• 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.
• Inherited operations can be refined by adding additional behavior.
Let us first discuss metadata. You are already familiar with metadata concept in your
database course. As you know, RDBMS uses metadata for storing information of
database tables. Basically, metadata is such set of data which describes other data. For
example, if you have to describe an object, you must have a description of the class
from which it is instantiated. Here, the data used to describe class will be treated as
metadata. You may observe that every real-world thing may have meta data, because
every real world thing has a description for them. Let us take the example of institutes 13
Modeling and their directors. You can store that school A is having X as its direct, School B is
having Y as its director, and so on. Now, you have concrete information to keep in
metadata that is every institute is having a director.
KEY
Object instances may be identified by an attribute (or combination of attributes) called
a key. A primary key is an attribute (or combination of attributes) that uniquely
identifies an object instance and corresponds to the identifier of an actual object.
For example, customer number would usually be used as the primary key for customer
object instances. Two, or more, attributes in combination sometimes may be used to
uniquely identify an object instance. For example, the combination of last name, first
name and middle initial might be used to identify a customer or employee object
instance. Here, you can say that sometimes more than one attribute gives a better
chance to identify an object. For example, last name alone would not suffice because
many people might have the same last name. First name would help but there is still a
problem with uniqueness. All three parts of the name are better still, although a
system generated customer or employee number is bests used as an identifier if
absolute uniqueness is desired. Possible Primary Keys that are not actually selected
and used as the primary keys are called candidate keys.
A secondary key is an attribute (or combination of attributes) that may not uniquely
identify an object instance, but can describe a set of object instances that share some
common characteristic. An attribute (customer type) might be used as a secondary
key to group customers as internal to the business organisation (subsidiaries or
divisions) or external to it. Many customers could be typed as internal or external at
the same time, but the secondary key is useful to identify customers for pricing and
customer service reasons.
When you define triggering rules, you are concerned only with the logic of the
operations, not execution efficiency, or the particular implementation of the rules.
You will implement and tune the rule processing later when you translate the logical
database model to a physical database implementation. Here, you should note that it is
important to avoid defining processing solutions (like defining special attributes to
serve as processing flags, such as a posted indicator for invoices) until all information
requirements have been defined in the logical object model, and fully understood.
1..n quantity
o..n
Product
Check Credit Card Cash
Card No
Verification Code
Bom ID Expire Date Cash Tendered Unit Price brand
Reg. Pn.
Check ID Id valid ()
Alternate Courses
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
2) Suppose that a computer is built out of one or more CPUs, Sound Card, and
Video. Model the system with representative classes, and draw the class
diagram
…………………………………………………………………………….
…………………………………………………………………………….
…………………………………………………………………………….
…………………………………………………………………………….
17
Modeling 3) Suppose that Window WithScrollbar class is a subclass of Window and has a
scrollbar. Draw the class diagram (relationship and multiplicity).
………………………………………………………………………….…
………………………………………………………………………….…
……………………………………………………………………………
………………………………………………………………………….…
………………………………………………………………………….…
…………………………………………………………………………….
1.8 SUMMARY
This Unit over basic aspects of object modeling which includes discussion model
based on objects (rather than functions) will be more stable over on a time hence the
object oriented designs are more maintainable. Object do not exist in isolation from
one another. In UML, there are different types of relationship (aggregation,
composition, generalization). This Unit covers aggregation, and emphasizes that
aggregation is the has-a or whole/part relationship. In this Unit we have also seen that
generalization means extracting common properties from a collection of classes and
placing them higher in the inheritance hierarchy, in a super class. We concluded the
Unit with a discussion on integrity constraints, and by giving an object model for sales
order system.
1.9 SOLUTIONS/ANSWERS
Check Your Progress 1
1) C 2) D 3) C 4) D
2)
Computer 1. * Computer
1. *
1. *
Sound Card
Video Card
18
3) Object Modeling
Window
19