Object-oriented Design - Florida A&M University

Download Report

Transcript Object-oriented Design - Florida A&M University

Object-oriented Design
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 1
Objectives




To explain how a software design may be
represented as a set of interacting objects
that manage their own state and operations
To describe the activities in the objectoriented design process
To introduce various models that can be
used to describe an object-oriented design
To show how the UML may be used to
represent these models
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 2
Topics covered



Objects and object classes
An object-oriented design process
Design evolution
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 3
Object-oriented development




Object-oriented analysis, design and programming
are related but distinct.
OOA is concerned with developing an object model
of the application domain.
OOD is concerned with developing an objectoriented system model to implement requirements.
OOP is concerned with realising an OOD using an
OO programming language such as Java or C++.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 4
Characteristics of OOD





Objects are abstractions of real-world or system
entities and manage themselves.
Objects are independent and encapsulate state and
representation information.
System functionality is expressed in terms of object
services.
Shared data areas are eliminated. Objects
communicate by message passing.
Objects may be distributed and may execute
sequentially or in parallel.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 5
Interacting objects
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 6
Advantages of OOD



Easier maintenance. Objects may be
understood as stand-alone entities.
Objects are potentially reusable components.
For some systems, there may be an obvious
mapping from real world entities to system
objects.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 7
Objects and object classes
An object is an entity that has a state and a defined set of
operations which operate on that state. The state is represented as a
set of object attributes. The operations associated with the object
provide services to other objects (clients) which request these
services when some computation is required.
Objects are created according to some object class definition. An
object class definition serves as a template for objects. It includes
declarations of all the attributes and services which should be
associated with an object of that class.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 8
The Unified Modeling Language




Several different notations for describing objectoriented designs were proposed in the 1980s and
1990s.
The Unified Modeling Language is an integration of
these notations.
It describes notations for a number of different
models that may be produced during OO analysis
and design.
It is now a de facto standard for OO modelling.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 9
Employee object class (UML)
Emp lo yee
n ame: s tring
ad dress : s tring
d ateOfBir th : Date
emp loy eeNo : integer
so cialSecurityNo : strin g
d epar tmen t: Dept
man ager: Employ ee
salar y : in teg er
statu s: {curren t, left, retired }
taxCod e: in teg er
. ..
jo in ()
leav e ()
retire ()
ch an geDetails ()
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 10
UML associations




Objects and object classes participate in
relationships with other objects and object classes.
In the UML, a generalised relationship is indicated
by an association.
Associations may be annotated with information that
describes the association.
Associations are general but may indicate that an
attribute of an object is an associated object or that
a method relies on an associated object.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 11
An association model
Emp lo yee
is -member-o f
Dep ar tmen t
is -man aged-by
man ag es
Man ag er
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 12
An object-oriented design process



Structured design processes involve
developing a number of different system
models.
They require a lot of effort for development
and maintenance of these models and, for
small systems, this may not be costeffective.
However, for large systems developed by
different groups design models are an
essential communication mechanism.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 13
Object identification



Identifying objects (or object classes) is the
most difficult part of object oriented design.
There is no 'magic formula' for object
identification. It relies on the skill, experience
and domain knowledge of system designers.
Object identification is an iterative process.
You are unlikely to get it right first time.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 14
A use case is a summary of scenarios for a single task or goal. An actor is who
or what initiates the events involved in that task. Actors are simply roles that
people or objects play. The picture below is a Make Appointment use case for
the medical clinic. The actor is a Patient. The connection between actor and use
case is a communication association (or communication for short).
•determining features (requirements). New use cases often generate new requirements as the
system is analyzed and the design takes shape.
•communicating with clients. Their notational simplicity makes use case diagrams a good way
for developers to communicate with clients.
•generating test cases. The collection of scenarios for a use case may suggest a suite of test case
for those scenarios
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 15
A Class diagram gives an overview of a system by showing its classes
and the relationships among them. Class diagrams are static -- they
display what interacts but not what happens when they do interact.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 16
•association -- a relationship between instances of the two classes. There is an association
between two classes if an instance of one class must know about the other in order to perform its
work. In a diagram, an association is a link connecting two classes.
•aggregation -- an association in which one class belongs to a collection. An aggregation has a
diamond end pointing to the part containing the whole. In our diagram, Order has a collection of
OrderDetails.
•generalization -- an inheritance link indicating one class is a superclass of the other. A
generalization has a triangle pointing to the superclass. Payment is a superclass of Cash, Check,
and Credit.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 17
Packages and object diagrams
To simplify complex class diagrams, you can group classes into packages. A package is a
collection of logically related UML elements. The diagram below is a business model in which
the classes are grouped into packages.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 18
A sequence diagram is an interaction diagram that details how operations are carried out -- what
messages are sent and when. Sequence diagrams are organized according to time. The time
progresses as you go down the page. The objects involved in the operation are listed from left to
right according to when they take part in the message sequence.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 19
Collaboration diagrams are also interaction diagrams. They convey the same information as
sequence diagrams, but they focus on object roles instead of the times that messages are sent. In
sequence diagram, object roles are the vertices and messages are the connecting links.
©Ian Sommerville 2004
Software Engineering, 7th edition. Chapter 14
Slide 20