Object orientation in design

Page 1

Object-Oriented Software Engineering

Chapter 4: Object-orientation in Design


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

2


Chapter’s Directory

Chapter 4: Object-orientation in Design

3


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

4


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

5


The OO Design Pyramid

responsibilities design

message design class and object design subsystem design

Chapter 4: Object-orientation in Design

6


What is UML?… The Unified Modelling Language is a standard graphical 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

7


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 standardization The objective of UML is to assist in software development

Chapter 4: Object-orientation in Design

8


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

9


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

10


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

Rectangle getArea resize

Rectangle height width

Rectangle

Rectangle

height width

height: int width: int

getArea resize

getArea(): int resize(int,int)

Chapter 4: Object-orientation in Design

11


Associations and Multiplicity‌ UML Multiplicity Multiplicity Notation

Association with Multiplicity

1 or leave blank

Employee

Zero or one

0..1

Employee

Customer

Zero or more

0..* or

*

Customer

One or more

1..*

University

Exactly 1

Specific range

7..9

Employee

Team

Works for

1

Works for

Department Department

Has

0..1

Makes

0..*

Makes

*

Offers

1..*

Has scheduled 7..9

Spouse

Payment Payment

Association Meaning An employee works for one and only one department.

An employee has either one or no spouse.

A customer can make no payment up to many payments.

Course

A university offers at least 1 course up to many courses.

Game

A team has either 7, 8, or 9 games scheduled

Chapter 4: Object-orientation in Design

12


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

If the interval has no upper bound, then * is used. Hence, 0..* and * mean the same thing

Employee

*

Secretary

*

Company 1..**

Company

Office

Person

Manager

BoardOfDirectors 0..1

0,3..8

*

*

Employee

BoardOfDirectors

Chapter 4: Object-orientation in Design

13


Labelling Associations… • Each association can be labelled, to make explicit the nature of the association • 2 types of labels: —Association name Employee

worksFor

*

Company

- “An employee works for a company”

—Role name Person

0,3..8 boardMember

*

BoardOfDirectors

- “A board of directors has either zero or 3 to 8 persons as board members” Chapter 4: Object-orientation in Design

14


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 Company

BoardOfDirectors

- “A company has a board of directors”

Chapter 4: Object-orientation in Design

15


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? Employee

*

worksFor

Company

Chapter 4: Object-orientation in Design

16


Labelling Associations Each association can be labelled, to make explicit the nature of the association Employee

*

Secretary

*

worksFor

Company 1..** supervisor

Company

Office

Person

Manager

BoardOfDirectors 0..1

0,3..8 boardMember

allocatedTo

*

*

Employee

BoardOfDirectors

Chapter 4: Object-orientation in Design

17


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

18


Analysing and Validating Associations‌ Avoid unnecessary one-to-one associations

Avoid this Person name

PersonInfo address email birthdate

Do this Person name address email birthdate

Chapter 4: Object-orientation in Design

19


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. Secretary

*

1..** supervisor

Chapter 4: Object-orientation in Design

Manager

20


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

AquaticAnimal

LandAnimal

typeOfFood

Carnivore

Herbivore

Chapter 4: Object-orientation in Design

21


Handling Multiple Discriminators Creating higher-level generalisation Animal habitat

AquaticAnimal typeOfFood

AquaticCarnivore

LandAnimal typeOfFood

AquaticHerbivore

LandCarnivore

LandHerbivore

Chapter 4: Object-orientation in Design

22


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 Vehicle

*

VehiclePart

Country

*

Region

Chapter 4: Object-orientation in Design

23


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

24


Composition • A composition is a strong kind of aggregation —if the aggregate is destroyed, then the parts are destroyed as well Building

*

Room

Chapter 4: Object-orientation in Design

25


Aggregation Hierarchy Vehicle

*

Chassis

BodyPanel

*

Door

*

Frame

Engine

Transmission

Chapter 4: Object-orientation in Design

Wheel

26


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

27


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

28


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.

Chapter 4: Object-orientation in Design

29


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.