object orientation in design

29
Object-Oriented Software Engineering Chapter 4: Object-orientation in Design

Upload: babar-bilal

Post on 21-Feb-2016

222 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Object orientation in design

Object-Oriented Software Engineering

Chapter 4: Object-orientation in Design

Page 2: 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

Page 3: Object orientation in design

Chapter 4: Object-orientation in Design 3

Chapter’s Directory

Page 4: Object orientation in design

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

Page 5: Object orientation in design

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

Page 6: Object orientation in design

Chapter 4: Object-orientation in Design 6

The OO Design Pyramid

responsibilitiesdesign

messagedesign

class and objectdesign

subsystemdesign

Page 7: Object orientation in design

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

Page 8: Object orientation in design

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

Page 9: Object orientation in design

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

Page 10: Object orientation in design

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

Page 11: Object orientation in design

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

Page 12: Object orientation in design

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

Page 13: Object orientation in design

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

Page 14: Object orientation in design

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

Page 15: Object orientation in design

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

Page 16: Object orientation in design

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

Page 17: Object orientation in design

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

Page 18: Object orientation in design

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

Page 19: Object orientation in design

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

Page 20: Object orientation in design

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

Page 21: Object orientation in design

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

Page 22: Object orientation in design

Chapter 4: Object-orientation in Design 22

Handling Multiple Discriminators

Animal

habitat

LandAnimalAquaticAnimal

AquaticCarnivore AquaticHerbivore LandCarnivore LandHerbivore

typeOfFood typeOfFood

Creating higher-level generalisation

Page 23: Object orientation in design

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

Page 24: Object orientation in design

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

Page 25: Object orientation in design

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

Page 26: Object orientation in design

Chapter 4: Object-orientation in Design 26

Aggregation Hierarchy

* *

*WheelTransmissionEngineFrame

DoorBodyPanelChassis

Vehicle

Page 27: Object orientation in design

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

Page 28: Object orientation in 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

Page 29: Object orientation in design

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.