Lecturer: Dr. AJ Bieszczad Chapter 66-1 Object-Oriented analysis and design Special nature of OO...

Preview:

Citation preview

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-1

Object-Oriented analysis and design

• Special nature of OO development

• Use cases

• Design with UML

• OO system design

• OO program design

• OO measurements

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-2

Object orientation

• identity

• abstraction

• classification

• encapsulation

• inheritance

• polymorphism

• persistence

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-3

Objects and classes

• Every object has a name (also called a reference or handle).

• Objects can have attributes (such as color, size, location).

• Objects can have operations or behaviors (such as takeoff, land, repair).

• Each object is an instance of a class.• A specific implementation of an operation for a

certain class is called a method.

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-4

Classification

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-5

Forming a hierarchy

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-6

Table 6.1: Tendency for change when using OO paradigm (Jacobson et al. 1995)

Characteristic of software product/project Probability for change

Objects derived from the application lowLong-lived information structures lowPassive object’s attribute mediumSequences of behavior mediumInterface with the outside world highFunctionality high

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-7

OO design• Usually uses an OO requirements representation• System design identifies and represents objects and classes,

plus details of each objects attributes and behaviors.• System design also identifies interactions and relationships.• Program design inserts computational features in the

models.• Program design inserts class library details.• Program design considers nonfunctional requirements to

enhance design.

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-8

OO and testing

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-9

Use cases

• Diagrams have four elements:– actors– cases– extensions– uses

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-10

Identifying participants• What users or groups use the system to perform a task?• What users or groups are needed so that the system can

perform its functions?• What external systems use the system to perform a task?• What external systems, users or groups send

information to the system?• What external systems, users or groups receive

information from the system?

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-11

Example: Service station

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-12

Service station use case diagram 1

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-13

Service station use case diagram 2

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-14

Service station use case diagram 3

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-15

UML and the OO process

• Workflow diagrams

• Object model

• Sequence diagrams

• Collaboration diagrams

• Package diagrams

• Component diagrams

• Deployment diagrams

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-16

UML support for development process

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-17

First cut at object classes

• Structures• External systems• Devices• Roles• Operating procedures• Places• Organizations• Things that are manipulated by the system to be built

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-18

Class box example

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-19

Inheritance relationship

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-20

Association relationship

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-21

Types of class relationships

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-22

UML notes and qualifies

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-23

Service Station – first take

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-24

Service Station – second take

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-25

Service Station – final cut

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-26

Class name: refuelCategory: serviceExternal documents:Export control: PublicCardinality: nHierarchy:

Superclasses: servicesAssociations:

fuel in association <name>Operation name: price

Public member of: refuelDocumentation:

// Calculates fuel final pricePreconditions:

gallons > 0Object diagram: (unspecified)

Semantics:final_price = gallons * priceObject diagram: (unspecified)

Concurrency: sequential

Public interface:Operations:

pricePrivate interface:

Attributes:gallonsprice

Implementation:Attributes:

gallonsprice

State machine: noConcurrency: sequentialPersistence: transient

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-27

Service Station – package diagram

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-28

Sequence Station – sequence diagram for the refuel use case

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-29

Service Station – collaboration diagram for the perking use case

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-30

State diagram example

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-31

State diagram for Fuel class

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-32

State diagram for Part class

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-33

State diagram for Inventory class

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-34

Activity diagram

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-35

Activity diagram for Inventory class

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-36

Guidelines for building classes

• What needs to be “processed” in some way?

• What items have multiple attributes?

• When do you have more than one object in a class?

• What is based on the requirements themselves, not derived from your understanding of the requirements?

• What attributes and operations are always applicable to a class or object?

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-37

Guidelines for identifying behaviors

• Imperative verbs

• Passive verbs

• Actions

• Things or reminded events

• Roles

• Operating procedures

• Services provided by an organization

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-38

Program design considerations

• Nonfunctional requirements

• Reused components

• Reusable components

• User interface requirements

• Data structure and management details

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-39

Transition from paper to screen

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-40

Possible design for new billing screen

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-41

Implementing classes using relational database

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-42

Observer pattern - relationships

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-43

Observer pattern – sequence diagram

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-44

Table 6.5: Lorenz and Kidd metrics collection in different phases of development.

Phase

Metric

RequirementsDescription

System Design Program Design Coding Testing

Number of scenarioscripts

X

Number of key classes X XNumber of support classes XAverage number ofsupport classes per keyclass

X

Number of subsystems X XClass size X X XNumber of operationsoverridden by a subclass

X X X X

Number of operationsadded by a subclass

X X X

Specialization index X X X X

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-45

Table 6.7: Where to capture OO metrics.

Phase

Metric

Use cases Classdiagrams

Inter-actiondiagrams

Class descrip-tions

Statediagrams

Packagediagrams

Number of scenario scripts XNumber of key classes XNumber of support classes XAverage number ofsupport classes per keyclass

X

Number of subsystems XClass size X XNumber of operationsoverridden by a subclass

X

Number of operationsadded by a subclass

X

Specialization index XWeighted methods in class XDepth of inheritance XNumber of children XCoupling between objects XResponse for a class XLack of cohesion inmethods

X

Average operation size XAverage number ofparameters per operation

X

Operation complexity XPercent public andprotected

X

Public access to datamembers

X

Number of root classes XFan-in/fan-out X

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-46

Object-oriented view of the Service Station

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-47

Class hierarchy for the Service Station

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-48

Table 6.6: Chidamber and Kemerer metrics collection in different phases of development.

Phase

Metric

System Design Program Design Coding Testing

Weighted methods perclass

X X X

Depth of inheritance X X XNumber of children X X XCoupling between objects X XResponse for a class X XLack of cohesion ofmethods

X X X

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-49

Measuring Service Station system design

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-50

Measuring Service Station program design

Lecturer: Dr. AJ Bieszczad

Chapter 6 6-51

Measuring from a sequence diagram

Recommended