You are on page 1of 25

UNIT- III

CHAPTER IN BOOK- 9
DAY- 19

-K. Indhu
SYLLABUS COVERED HERE
• Corollaries-II
• Design-Patterns

17-FEB-14 K. INDHU 2
GOALS
1. Corollaries-> derived from Axioms
2. Coupling
– What is Coupling?
– Types of Coupling
3. Cohesion
4. Corollaries In Detail
5. Designing With Inheritance
6. Design-Patterns
7. Façade Design Pattern

17-FEB-14 K. INDHU 3
COROLLARIES

17-FEB-14 K. INDHU 4
WHAT IS COUPLING?
• Coupling is a measure of the strength of association
established by a connection from one object to another object.

• PREFERRED TO HAVE:- A change to one component of a system


should have a minimal impact on other components.

• Strong Coupling among objects complicates a system because


the class is harder to understand when highly inter-related with
other classes.

• Object Oriented Design has two types of coupling:-


1. INTERACTION COUPLING
2. INHERITANCE COUPLING

17-FEB-14 K. INDHU 5
TYPES OF COUPLING
1. INTERACTION COUPLING->
– involves the amount & complexity of messages between
components.
– It is desirable to have little interaction.
– The general guideline is to keep the messages- (a) as simple and
(b) In-Frequent as possible.
– The message passed between objects should be SIMPLE and
the No. of Messages sent/received should be LESS.
2. INHERITANCE COUPLING->
– Inheritance is a form of coupling between super and subclasses.
– A subclass is coupled to its super-class in terms of attributes and
methods.
– HIGH INHERITANCE COUPLING IS DESIRABLE.

17-FEB-14 K. INDHU 6
COUPLING-
DIAGRAMMATIC REPRESENTATION

17-FEB-14 K. INDHU 7
COHESION
• Cohesion deals with interactions between objects or
interactions within a single object.
• COHESION MEANS “SINGLE-PURPOSENESS” OF AN
OBJECT.

1. METHOD COHESION means that a method should carry


ONLY ONE FUNCTION. A method that carries multiple
functions is undesirable.
2. CLASS COHESION means that all class’s methods and
attributes must be highly cohesive.
• Cohesion helps in designing classes that have very specific
goals and clearly defined purposes.

17-FEB-14 K. INDHU 8
COROLLARIES IN DETAIL
• Corollary 1- Uncoupled Design with Less Information
Content
– The main goal here is to maximize objects (or software
components) cohesiveness.

– Coupling Explanation

– Cohesion Explanation

– HIGHLY COHESIVE OBJECTS CAN IMPROVE COUPLING


BECAUSE ONLY A MINIMAL AMOUNT OF ESSENTIAL
INFORMATION NEED TO BE PASSED BETWEEN OBJECTS.

17-FEB-14 K. INDHU 9
COROLLARIES IN DETAIL
• Corollary 2 - Single Purpose
– Each class must have a purpose, as was explained in a
previous chapter.

– We should not create classes just like that which serve no


purpose.

– When you document a class, you should be able to easily


explain its purpose in a sentence or two.

– EACH METHOD in a Class must provide ONLY ONE SERVICE-


SIMPLER SERVICE.

17-FEB-14 K. INDHU 10
COROLLARIES IN DETAIL
• Corollary 3- Large Number of Simpler Classes, Reusability
– A great benefit results from having a large number of simpler classes.

– The less specialized the classes are, the more likely future problems
can be solved by a re-combination of existing classes and adding
minimal number of sub classes.

– A complex, poorly designed class is just so much dead weight and


usually cannot be re-used.
– THE BASIC GUIDELINE IS:- “THE SMALLER ARE OUR CLASSES, THE
BETTER ARE OUR CHANCES OF RE-USING THEM IN OTHER PROJECTS.
LARGE AND COMPLEX CLASSES ARE TOO SPECIALIZED TO BE RE-
USED.”

17-FEB-14 K. INDHU 11
COROLLARIES IN DETAIL
• Corollary 4- Strong Mapping
– As the model progresses from analysis to
implementation, more detail is added, but it remains
essentially the same.

– A strong mapping links classes identified during


analysis and classes designed during the design phase.

– THERE MUST BE A STRONG ASSOCIATION(MAPPING)


BETWEEN THE PHYSICAL SYSTEM (ANALYSIS'S
OBJECT) AND LOGICAL DESIGN (DESIGN'S OBJECT).

17-FEB-14 K. INDHU 12
COROLLARIES IN DETAIL
• Corollary 5- Standardization
– The concept of design patterns might provide a way
for standardization by->
• capturing the design knowledge,
• documenting it
• and storing it in a repository
• that can be shared and reused in different applications.

– PROMOTE STANDARDIZATION BY DESIGNING INTER-


CHANGEABLE COMPONENTS AND REUSING EXISTING
CLASSES OR COMPONENTS.

17-FEB-14 K. INDHU 13
COROLLARIES IN DETAIL
• Corollary6- Designing With Inheritance
– Common behavior(methods) must be moved to superclasses.
– The superclass-subclass structure must make logical sense.
– USE MORE INHERITANCE. AVOID INHERITING
INAPPROPRIATE BEHAVIORS.

17-FEB-14 K. INDHU 14
DESIGNING WITH INHERITANCE
• Say we are developing an application for the
government that manages the licensing procedure
for a variety of regulated entities.

• Let us focus on just two types of entities:-


• (i) MOTOR VEHICLES & (ii) RESTAURANTS.

03-DEC-13 K. INDHU 15
DESIGNING WITH INHERITANCE

03-DEC-13 K. INDHU 16
DESIGNING WITH INHERITANCE
• Six Months Later.........

03-DEC-13 K. INDHU 17
DESIGNING WITH INHERITANCE-
SIX MONTHS LATER HOW TO IMPLEMENT

03-DEC-13 K. INDHU 18
DESIGNING WITH MULTIPLE INHERITANCE-
FINAL PRODUCT

03-DEC-13 K. INDHU 19
DESIGNING WITH SINGLE INHERITANCE-
FINAL PRODUCT

03-DEC-13 K. INDHU 20
DESIGN PATTERNS
• Design Patterns are devices:-
– that allow systems to share knowledge about their
design,
– by describing commonly recurring structures of
communicating components that solve a general
design problem within a particular context.

• Design Patterns provide a mechanism for:-


– capturing and,
– describing commonly recurring design ideas
– that solve a general design problem.

17-FEB-14 K. INDHU 21
WITHOUT FAÇADE DESIGN PATTERN

17-FEB-14 K. INDHU 22
WITH FAÇADE DESIGN PATTERN

17-FEB-14 K. INDHU 23
SO FAR WHAT WE STUDIED…
• What do you mean by Coupling?
• What are the types of Coupling?
• What do you mean by Cohesion?
• What are 6 Corollaries in Detail?
• How to design by Inheritance?
• What is a Design Pattern?

17-FEB-14 K. INDHU 24
HAPPY LEARNING!!!

You might also like