y
nl
O
se
U
tre
en
Session: 2 C
h
ec
Object-oriented Design
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited.
y
nl
Explain Object-oriented design (OO Design)
O
Describe Responsibility-driven Design (RDD)
se
Explain Agents, Classes, and Instances
U
tre
Describe Methods, Responsibilities, and Modules
en
Explain Generalization, Specialization, and Patterns
Explain Coupling and Cohesion C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 2
y
nl
O
se
Technique that focuses on designing the data and
U
the interfaces to it.
tre
en
C
h
Process of creating a system where objects coordinate
ec
or interact with each other to accomplish a task
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 3
y
nl
The input for OO Design is provided by Object-oriented
O
analysis in the form of:
se
U
System
tre
Conceptual
Use cases Sequence
en
models
Diagrams (SSD)
C
h
ec
User Interface
pt
Data models
Documentation
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 4
y
nl
The various tasks involved in OO Design are as follows:
O
Defining classes and objects from conceptual diagrams
se
U
tre
Identifying the attributes of an object
en
C
Using design patterns to find a solution to a problem
h
ec
Defining the application framework
pt
rA
Define the data model for persistent storage of objects or data
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 5
y
nl
O
se
U
The end products of OO Design are the system diagrams
such as
tre
en
Sequence Diagrams
C
h
ec
Class Diagrams
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 6
y
nl
A design technique
O
se
Based on delegation of responsibilities and
U
determination of components responsible for
tre
executing the responsibilities
en
C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 7
y
To describe each component and its
nl
responsibility, the design team prepares small
O
index cards.
se
U
tre
en
C
h
ec
pt
rA
Each card contains the name of the software component, the
Fo
responsibilities and names of other components to which it interacts.
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 8
y
nl
Based on RDD, several other software concepts have
O
been defined that are as follows:
se
Communities of Agents
U
Classes and Objects
tre
Messages and Methods
en
Responsibilities
Modules C
h
Generalization and Specialization
ec
Patterns
pt
rA
Coupling and Cohesion
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 9
y
An object-oriented program is viewed as a community
nl
O
of interacting agents called objects.
se
U
Each object plays a unique role and provides services
tre
to or performs a task for the other members of the
en
community.
C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 10
y
nl
Consider an example where a person named Bob
O
wants to send a cake to a friend named Brian.
se
U
tre
en
C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 11
y
nl
A class or a category is a group of people or things
O
having common characteristics
se
U
The figure shows various objects arranged according to
tre
their category or class.
en
C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 12
y
nl
An object is one copy of the class.
O
se
Object can also be referred to as an instance of a class.
U
tre
The figure shows two objects of class Baker namely b1
en
and b2 and the value of Name for b1 is William and
that of b2 is Roger. C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 13
y
nl
A method is a set of steps or instructions, or a
O
procedure to accomplish something
se
U
Message is a set of words, a phrase, or statement to
tre
convey something
en
C
The figure shows how the objects pass messages to
h
ec
each other to fulfill a task.
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 14
y
nl
Objects communicate with each other by invoking
O
methods and passing messages or arguments to the
se
methods to complete a task
U
tre
The message passing
en
and method invocation
can also be better C
h
ec
understood from the
figure.
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 15
y
nl
In OOP, describe the behavior of objects as
O
responsibilities
se
U
The figure shows the responsibilities of various agents
tre
in the cake delivery process.
en
C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 16
y
To solve complex problems divide the problem into
nl
smaller units or modules
O
se
The figure shows the approximate time it took to Bob
U
to deliver the cake when he does everything himself.
tre
en
C
h
ec
pt
rA
Fo
Total time taken (approx.) 2 hours and 50 minutes
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 17
y
nl
The figure shows the time it took Bob when the task
O
was divided among other agents.
se
U
tre
en
C
h
ec
This shows that by dividing the task between multiple
pt
people, Bob was able to achieve his goal in almost half
rA
the time than he would have done it himself
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 18
y
nl
The figure shows the concept of generalization and
O
specialization.
se
U
tre
en
C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 19
y
nl
A shape, model, or structure appearing again and again
O
to create a design
se
U
The figure shows the situation of a client making
tre
request through a proxy.
en
C
h
ec
pt
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 20
y
nl
Coupling is the degree to which the components know
O
about each other
se
U
Coupling can be loose or tight
tre
en
In tightcoupling
Loose coupling,
means
the a group
of components
components arewhich
largely
can be C
h
ec
operate independent
dependent on each other
of each
pt
other
rA
Fo
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 21
y
Cohesion deals with a single component and how
nl
focused it is on a specific task
O
se
The figures show a less cohesive component and a
U
highly cohesive component.
tre
en
C
h
ec
pt
rA
Fo
Less Cohesive Highly Cohesive
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 22
Responsibility-driven design is a design technique based on
y
nl
delegation of responsibilities and determination of components
O
responsible for executing the responsibilities.
se
An object-oriented program is viewed as a community of
U
interacting agents called objects.
tre
A class is a structure that defines and encloses the data
members and methods pertaining to a particular entity. An
en
instance is one copy of the class.
C
The commonly used method of solving complex problems is to
h
divide the problem into smaller units called modules.
ec
A pattern is a solution to a problem which has been used
pt
effectively in a similar problem encountered earlier.
rA
Coupling is the degree to which the components know about
Fo
each other. Cohesion is the degree to which a particular
component is designed for specific and focused purpose.
Version 1.0 © 2012 Aptech Limited. Object-Oriented Programming Concepts / Session 2 23