Object orientation in design
-
Upload
babar-bilal -
Category
Documents
-
view
218 -
download
0
description
Transcript of Object orientation in design
Object-Oriented Software Engineering
Chapter 4: Object-orientation in Design
Chapter 4: Object-orientation in Design 2
Table of Contents
• The OO Design Pyramid• What is UML?• What Constitutes A Good Model?• Essentials of UML Class Diagrams• Associations and Multiplicity• Analyzing and Validating Associations
Chapter 4: Object-orientation in Design 3
Chapter’s Directory
Chapter 4: Object-orientation in Design 4
The OO Design Pyramid…
The subsystem layer• Contains a representation of each of the
subsystems that enable the software to achieve its customer-defined requirements
The class and object layer• Contains the class hierarchies that enable the
system to be created using generalizations• Contains representations of each object
Chapter 4: Object-orientation in Design 5
The OO Design Pyramid…
The message layer• Contains the design details that enable each object
to communicate with its collaborators• Establishes the external and internal interfaces for
the system
The responsibilities layer• Contains the data structure and algorithmic design
for all attributes and operations for each object
Chapter 4: Object-orientation in Design 6
The OO Design Pyramid
responsibilitiesdesign
messagedesign
class and objectdesign
subsystemdesign
Chapter 4: Object-orientation in Design 7
What is UML?…
The Unified Modelling Language is a standardgraphical language for modelling object oriented software
• At the end of the 1980s and the beginning of 1990s, the first object-oriented development processes appeared
• The proliferation of methods and notations tended to cause considerable confusion
• Two important methodologists Rumbaugh and Booch decided to merge their approaches in 1994
—They worked together at the Rational Software Corporation
Chapter 4: Object-orientation in Design 8
What is UML?
• In 1995, another methodologist, Jacobson, joined the team
—His work focused on use cases • In 1997 the Object Management Group (OMG)
started the process of UML standardizationThe objective of UML is to assist in software development
Chapter 4: Object-orientation in Design 9
What Constitutes A Good Model?
A model should• Use a standard notation • Be understandable by clients and users • Lead software engineers to have insights about the
system• Provide abstraction (eliminate complexity)
Models are used:• To help create designs• To permit analysis and review of those designs • As the core documentation describing the system
Chapter 4: Object-orientation in Design 10
Essentials of UML Class Diagrams
The main symbols shown on class diagrams are:• Classes
- represent the types of data themselves• Associations
- represent linkages between instances of classes• Attributes
- are simple data (characteristics) found in classes and their instances
• Operations- represent the functions performed by the classes and
their instances• Generalisations
- group classes into inheritance hierarchies
Chapter 4: Object-orientation in Design 11
Classes
A class is simply represented as a box with the name of the class inside
• The diagram may also show the attributes and operations
Rectangle
height: intwidth: int
getArea(): intresize(int,int)
Rectangle
heightwidth
getArearesize
Rectangle
heightwidth
Rectangle
getArearesize
Rectangle
Chapter 4: Object-orientation in Design 12
Associations and Multiplicity…Multiplicity Multiplicity
Works for
0..1Has
0..*Makes
UML Notation Association with Multiplicity Association Meaning
Exactly 11or
leave blank
DepartmentEmployee 1Works for
DepartmentEmployee
An employee works for one and only one department.
Zero or one 0..1 SpouseEmployeeAn employee has either one or no
spouse.
Zero or more
0..*or
*
PaymentCustomer
PaymentCustomerMakes *
A customer can make no payment
up to many payments.
One or more 1..* CourseUniversityOffers 1..* A university
offers at least 1 course up to
many courses.
Specific range 7..9 GameTeam 7..9
Hasscheduled A team has either
7, 8, or 9 games scheduled
Chapter 4: Object-orientation in Design 13
Associations and Multiplicity
An association is used to show how two classes are related to each other
• Symbols indicating multiplicity are shown at each end of the association
0,3..8 ******
Employee
*
* *****1..*
*0..1
Secretary
Office
Person
Company
Employee Company
Manager
BoardOfDirectors
BoardOfDirectors
If the interval has no upper bound, then * is used. Hence, 0..* and * mean the same thing
Chapter 4: Object-orientation in Design 14
Labelling Associations…
• Each association can be labelled, to make explicit the nature of the association
• 2 types of labels:—Association name
- “An employee works for a company”
—Role name
- “A board of directors has either zero or 3 to 8 persons as board members”
* worksForEmployee Company
boardMember
0,3..8 ******Person BoardOfDirectors
Chapter 4: Object-orientation in Design 15
Labelling Associations…
• You could omit the association name and role name, then consider that an association’s name is simply has by default
• Provided the meaning might be clear by simply looking at the two classes
- “A company has a board of directors”
Company BoardOfDirectors
Chapter 4: Object-orientation in Design 16
Labelling Associations…
• A good rule of thumb is:—Add sufficient names to make the
association clear and unambiguous —Not necessary to add both role names and
association names—If “employer” is added next to the company,
is it sufficient?—Or instead, “workFor” would sound better?
* worksForEmployee Company
Chapter 4: Object-orientation in Design 17
Labelling Associations
Each association can be labelled, to make explicit the nature of the association
*supervisor
*****1..*
* worksFor
*allocatedTo0..1
boardMember
0,3..8 ******
Employee
Secretary
Office
Person
Company
Employee Company
Manager
BoardOfDirectors
BoardOfDirectors
Chapter 4: Object-orientation in Design 18
Analysing and Validating Associations…
• One-to-one—For each company, there is exactly one board
of directors—A board is the board of only one company—A company must always have a board
Company BoardOfDirectors
Chapter 4: Object-orientation in Design 19
Analysing and Validating Associations…
Avoid unnecessary one-to-one associations
Avoid this Do this
Person
nameaddressemailbirthdate
Person
name
PersonInfo
addressemailbirthdate
Chapter 4: Object-orientation in Design 20
Analysing and Validating Associations…
•Many-to-many—A secretary can work for many managers—A manager can have many secretaries—Secretaries can work in pools—Managers can have a group of secretaries—Some managers might have zero secretaries.
*supervisor
*****1..*Secretary Manager
Chapter 4: Object-orientation in Design 21
Generalisation
Specialising a superclass into two or more subclasses
• The discriminator is a label that describes the criteria used in the specialization
Animal Animal
habitat typeOfFood
HerbivoreCarnivoreLandAnimalAquaticAnimal
Chapter 4: Object-orientation in Design 22
Handling Multiple Discriminators
Animal
habitat
LandAnimalAquaticAnimal
AquaticCarnivore AquaticHerbivore LandCarnivore LandHerbivore
typeOfFood typeOfFood
Creating higher-level generalisation
Chapter 4: Object-orientation in Design 23
More Advanced Features: Aggregation
• Aggregations are special associations that represent ‘part-whole’ relationships.
—The ‘whole’ side is often called the assembly or the aggregate
—This symbol is a shorthand notation association named isPartOf
****
****** Region
VehiclePart
Country
Vehicle
Chapter 4: Object-orientation in Design 24
When to Use an Aggregation
As a general rule, you can mark an association as an aggregation if the following are true:
• You can state that—the parts ‘are part of’ the aggregate—or the aggregate ‘is composed of’ the parts
• When something owns or controls the aggregate, then they also own or control the parts
Chapter 4: Object-orientation in Design 25
• A composition is a strong kind of aggregation —if the aggregate is destroyed, then the parts are
destroyed as well
Composition
***** RoomBuilding
Chapter 4: Object-orientation in Design 26
Aggregation Hierarchy
* *
*WheelTransmissionEngineFrame
DoorBodyPanelChassis
Vehicle
Chapter 4: Object-orientation in Design 27
Summary
At the completion of this chapter, you have learnt:
• What UML is• Features and functionality of OOD• Application in software design
Chapter 4: Object-orientation in Design 28
Review Questions…
Draw diagrams to link the following classes using aggregation, inheritance and multiplicity where appropriate
(a) Village, Street, House, Shop, Road(b) University Staff, Academic, Administrator,
Technician (c) Subscriber, Paying Subscriber, Complimentary
Subscriber, Individual Paying Subscriber, Corporate Paying Subscriber
(d) Zoon, Animal, Bird, Mammal, Reptile, Cage, Keeper
(e) Estate, Building, House, Shop Unit, Room, Window, Door, Wall, Floor, Ceiling
Chapter 4: Object-orientation in Design 29
Review Questions
Draw a class diagram, including class attributes, to represent the information given in the paragraph below:
A dental surgery keeps information about its patient, who may be either private or health service. For each patient the surgery records the name, address, phone number, date of birth, and either the health service number or the payment method.