You are on page 1of 20

UNIT- II

CHAPTER IN BOOK- 8
DAY- 16

-K. Indhu
SYLLABUS COVERED HERE
• Identifying Object Relationships
• Associations
• Super – Sub Class
• Aggregation – I

31-JAN-14 K. INDHU 2
GOALS
• Few Quote on Object Relationship by Researchers
• Introduction on Identifying Object Relationships
1. Association
– What?
– Diagrammatic Representation
– Guidelines for identifying Associations
– Common Association Patterns
– Eliminate Unnecessary Associations
2. Super – Sub Class Relationship
– What?
– Guidelines for Identifying Super – Sub Class Relationship
– Multiple Inheritance
3. Aggregation
– What?
– Properties of Aggregation

7-FEB-14 K. INDHU 3
FEW QUOTES BY RESEARCHERS
• “Objects contribute to the behavior of the system
by collaborating with one another.”
• —Grady Booch

• “In OO environment, an application is the


interactions and relationships among its domain
objects.”

• “All objects stand in relationship to others, on


whom they rely for services and controls.”
7-FEB-14 K. INDHU 4
IDENTIFYING OBJECT RELATIONSHIPS
• The relationship among objects is based on the assumptions each
makes about the other objects.

• Three types of relationships among objects are:-

1. Association:-
– How are objects associated (related)? This information will guide us in
designing classes.
2. Super-Sub Structure (also known as generalization hierarchy):-
– How are objects associated into superclasses and subclasses? This
information provides us the direction of inheritance.
3. Aggregation and a-part-of structure:-
– What is the composition of complex classes? This information guides us
in defining mechanism like object-within-object.

7-FEB-14 K. INDHU 5
ASSOCIATIONS
• Association represents a physical or conceptual connection
between two or more objects.

• A reference from one class to another is an association.

• Basically a dependency between two or more classes is an


association.

• For example, Jackie works for John.

• Some associations are implicit or taken from general


knowledge.

7-FEB-14 K. INDHU 6
ASSOCIATION
-DIAGRAMMATIC REPRESENTATION

7-FEB-14 K. INDHU 7
GUIDELINES
- FOR IDENTIFYING ASSOCIATIONS
• Identifying Associations begins by analyzing the
INTERACTIONS between classes.

• The below questions can help us to identify associations:-

– Is the class capable of fulfilling the required task by itself?


– If not what does it need?
– From what other class can it acquire what it needs?

• Answering the above questions help us identify association.

7-FEB-14 K. INDHU 8
GUIDELINES
- FOR IDENTIFYING ASSOCIATIONS
• A dependency between two or more classes may be an association.

• A reference from one class to another is an association.

• Association often appears as a verb in a problem statement and


represents relationship between classes.

• For example a pilot can fly planes.

• Association often corresponds to verb or prepositional phrases such


as part of, next to, works for, contained in, etc.

7-FEB-14 K. INDHU 9
COMMON ASSOCIATION PATTERNS
• Common association patterns include:-
1. Location Association: next To, part of, contained in,
ingredient of etc. .
– For example cheddar cheese is an ingredient of the French
soup.
2. Communication association: talk to, order to.
• For example, a customer places an order with an
operator person.

7-FEB-14 K. INDHU 10
ELIMINATE UNNECESSARY ASSOCIATIONS
1. Implementation Association:-
– Defer (postpone) implementation-specific associations to the design phase.->
POSTPONE INTERFACE RELATED ASSOCIATIONS TO DESIGN PHASE.
– Implementation Associations are concerned with the implementation or
design of the class within certain programming or development environments.

2. Ternary Association:-
– Ternary or n-ary association is an association among n-classes.
– Ternary Association complicate the representation.

3. Directed Actions / Derived Association:-


– Derived Associations can be defined in terms of other associations.
– Since they are redundant, avoid these type of associations.

7-FEB-14 K. INDHU 11
DERIVED ASSOCIATION EXAMPLE

7-FEB-14 K. INDHU 12
SUPER-SUB CLASS RELATIONSHIIPS
• The super-sub class relationship represents the inheritance relationship
between related classes.

• SuperClass-subclass relationships is also known as generalization hierarchy.

• CLASS HIERARCHY DEFINITION-> The Class Hierarchy determines the lines


of inheritance between classes.

• Recall that at the top of the class hierarchy is the most general class, and
from it descend all other, more specialized classes.

• Sub-classes are more specialized versions of their super-classes.

• Parent Class (Base Class) is also known as Super Class.

7-FEB-14 K. INDHU 13
GUIDELINES FOR IDENTIFYING:-
SUPER-SUB CLASS RELATIONSHIPS
1. Top – Down:-
• Look for noun phrases composed of various adjectives in a class name.

• Example, (i) Military Aircraft & Civilian Aircraft.


• (ii) Adult Membership & Senior Membership.

• Only specialize when the sub classes have significant DISTINCT


BEHAVIOR.

• For example, a phone operator employee can be represented as a


cook, as well as a clerk or manager because they all have similar
behaviors.

7-FEB-14 K. INDHU 14
GUIDELINES FOR IDENTIFYING:-
SUPER-SUB CLASS RELATIONSHIPS
2. Bottom - Up:-
• Look for classes with similar attributes or methods.

• Group them by moving the common attributes and methods to


super class.

• The Sub Class will have only certain attributes and methods
specific to it.

• Do not force classes to fit a preconceived generalization


structure. That is, for the sake of creating generalization do not
create classes.

7-FEB-14 K. INDHU 15
GUIDELINES FOR IDENTIFYING:-
SUPER-SUB CLASS RELATIONSHIPS
3. Re-usability:-
• Move attributes and methods as high as possible in the
hierarchy.

• At the same time do not create very specialized classes at the


top of hierarchy.

• This balancing act can be achieved through several iterations.

• This process ensures that we design objects that can be re-


used in another application.

7-FEB-14 K. INDHU 16
GUIDELINES FOR IDENTIFYING:-
SUPER-SUB CLASS RELATIONSHIPS
4. Multiple Inheritance:-
• Avoid excessive use of multiple inheritance.

• It is also more difficult to understand programs written in multiple


inheritance system.

• One way to achieve the benefits of multiple inheritance is to inherit


from the most appropriate class and add an object of other class as
an attribute.

• In essence, a multiple inheritance can be represented as an


aggregation of a single inheritance and aggregation. This meta model
reflects this situation.

7-FEB-14 K. INDHU 17
A-PART-OF RELATIONSHIP- AGGREGATION
• A-part-of relationship, also called aggregation,
represents the situation where a class consists of several
component classes.
• This does not mean that the class behaves like its parts.
• For example, a car consists of many other classes, one
of them is a radio, but a car does not behave like a
radio.

7-FEB-14 K. INDHU 18
A-PART-OF RELATIONSHIP- AGGREGATION
• Two major properties of a-part-of relationship are:
– Transitivity:-
• If A is part of B and B is part of C, then A is part of C.
• For example, a carburetor is part of an engine and an engine
is part of a car; therefore, a carburetor is part of a car.
– Anti-Symmetry:-
• If A is part of B, then B is not part of A.
• For example, an engine is part of a car, but a car is not part
of an engine.

7-FEB-14 K. INDHU 19
HAPPY LEARNING!!!

You might also like