Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects •...

37
1 1 © Wolfgang Emmerich, 1999 Object-Orientation Wolfgang Emmerich 2 © Wolfgang Emmerich, 1999 Outline Problem of software system complexity Approaching a solution Human limitations Underlying principles Development of the object-oriented approach Assessment of object-orientation

Transcript of Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects •...

Page 1: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

1

1© Wolfgang Emmerich, 1999

Object-Orientation

Wolfgang Emmerich

2© Wolfgang Emmerich, 1999

Outline

■ Problem of software system complexity■ Approaching a solution

• Human limitations• Underlying principles

■ Development of the object-orientedapproach

■ Assessment of object-orientation

Page 2: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

2

3© Wolfgang Emmerich, 1999

Software System Complexity

■ “Consisting of or comprehending variousparts united or connected together;formed by a combination of differentelements”

■ Any sizeable system:• developed by a team in a lengthy process,• impossible for individual to comprehend

fully,• difficult to document and test,• potentially inconsistent or incomplete,• subject to change.

■ But : Software engineering cannot yetprovide fundamental laws to explainphenomena and approaches

4© Wolfgang Emmerich, 1999

Reasons for Complexity

■ Grady Booch’s four reasons forcomplexity of software-intensive systems:

1 Nature of the problem domain• requirements,• decay of systems

2 Complexity of process• management problems,• need for simplicity

Page 3: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

3

5© Wolfgang Emmerich, 1999

Reasons for Complexity (continued)

3 Dangerous potential for flexibility ofsoftware• “Software is flexible and expressive and thus

encourages highly demanding requirements,which in turn lead to compleximplementations which are difficult toassess”

4 Characterising behaviour of systems• “The task of the software development team

is to engineer the illusion of simplicity”

6© Wolfgang Emmerich, 1999

Systems and Subsystems

■ “An organised or connected group ofobjects; a whole composed of parts inorderly arrangement according to somescheme or plan”

■ System:• boundary• environment• character• emergent property

■ Systems: interconnected subsystems■ Potential for inconsistency and

incongruity

Page 4: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

4

7© Wolfgang Emmerich, 1999

Attributes of Complex Systems

■ Booch’s five attributes of a complexsystem:• Hierarchical and interacting subsystems• Arbitrary determination of primitive

components• Stronger intra-component than inter-

component links• Combine and arrange examples of a few

kinds of subsystems• Evolution from simple to complex working

systems

8© Wolfgang Emmerich, 1999

Simplifying Complex Systems

■ Usefulness of abstractions common tosimilar activities, e.g. driving differentkinds of motor vehicle

■ Multiple orthogonal hierarchies e.g.structure and control system

■ Prominent hierarchies in object-orientation• “class structure”• “object structure”

■ e. g. engine types, engine in a specific car

Page 5: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

5

9© Wolfgang Emmerich, 1999

C1

C2

C3

C4

C5

C6

C7

D1

D2 D3

D4

D5 D6

D7

D8

Class vs. Object Structure

Objects

Classes

10© Wolfgang Emmerich, 1999

Approaching a Solution

■ Hampered by human limitations:• dealing with complexities• memory• communications

■ Principles that will provide basis fordevelopment:• Abstraction• Hierarchy• Decomposition

Page 6: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

6

11© Wolfgang Emmerich, 1999

Abstraction & Hierarchy

■ Concepts of fundamental importance■ Abstraction: assists people’s

understanding• grouping,• generalising,• ‘chunking’

of information or ideas.■ Hierarchy:

• Recognition of higher and lower orders,• Accumulation of attributes at higher level,• Association of fewer attributes with lower

level and greater n mber

12© Wolfgang Emmerich, 1999

Decomposition

■ Handling complexity on the principle of‘divide and conquer’

■ Two forms of decomposition:• process-oriented: according to steps /

functions• object-oriented: according to behaviour of

autonomous objects■ Both valid, but current claims for

superiority of OO• stronger framework• reuse of common abstractions• resilient under change

Page 7: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

7

13© Wolfgang Emmerich, 1999

Transaction

Gettransaction

Open Withdraw

PassbookOpen

CheckingOpen

BonusOpen

PassbookWithdraw

CheckingWithdraw

BonusWithdraw

PassbookDeposit

CheckingDeposit

BonusDeposit

Deposit

A function/data composition

14© Wolfgang Emmerich, 1999

An object-oriented Decomposition

Other object(s)

Open Deposit

Withdraw

Account

ihs ihsihs

Passbook Account

Checking Account

Bonus Account

ihs

Page 8: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

8

15© Wolfgang Emmerich, 1999

Market Open

Market Deposit

Market Withdraw

Transaction

Gettransaction

Open Withdraw

PassbookOpen

CheckingOpen

BonusOpen

PassbookWithdraw

CheckingWithdraw

BonusWithdraw

PassbookDeposit

CheckingDeposit

BonusDeposit

Deposit

Adding a new Market Account

Deposit

16© Wolfgang Emmerich, 1999

MarketAccount

Other object(s)

Open Deposit

Withdraw

Account

ihs ihsihs

Passbook Account

Checking Account

Bonus Account

ihs

Adding a new Market Account

Page 9: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

9

17© Wolfgang Emmerich, 1999

Class structureObject structure

Class structureObject structure

Model of OO Development

Module architectureProcess architecture

Class structureObject structure

LogicalModel

PhysicalModel

Static ModelDynamic Model

18© Wolfgang Emmerich, 1999

Simula-67

Information Hiding

Sun ONC

Programming LanguagesDistributed Systems Software Engineering

Time

1970

1980

1990

DCOM UML

DCE

COM

Smalltalk

Eiffel

CORBA

C++

OOAD

Java

History of Object-Orientation

Page 10: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

10

19© Wolfgang Emmerich, 1999

Structured Methods

■ SSADM (Cutts 1987), SA (de Marco 1978),SADT (Ross 1977).

■ Existing structure methods treatseparately :• functions (behaviour) and• data (information held)

■ Problems:• Difficulties with maintenance (because need

knowledge of data storage)• Division of knowledge (whereby “what” is

transformed into “how”)■ Instabilit y of functions

20© Wolfgang Emmerich, 1999

Object-Oriented Methods

■ Better able to cope with changeItem Freq. Of ChangesObject from application LowLong-lived information structures LowPassive object’s attribute MediumSequence of behavior MediumInterface with outside world HighFunctionality High

■ OO focuses analysis on problem domain■ Promotes reuse■ Continuity of representation

Page 11: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

11

21© Wolfgang Emmerich, 1999

Suggested object-oriented Methods

■ Coad & Yourdon (91) for OOA■ Booch (94) also for OOA■ Jackson (83) for system design■ Jacobson (92) OOSE■ Approach of this course based on

Jacobson because employs ‘use cases’throughout• essential user role• focus on domain• integration in process

■ All likely to be superseded by ‘retreads’employing the UML

22© Wolfgang Emmerich, 1999

Drawbacks of OO

■ Large scale reuse not yet achieved

■ Few available reusable libraries

■ Managing reusable libraries is a problem

■ Extensive retraining before pervasive

Page 12: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

12

23© Wolfgang Emmerich, 1999

ComplexSoftwareSystem

ComplexReal-world

System

Functionaldecomposition

OBJECTORIENTATION

Abstraction Hierarchy Decomposition

Summary

24© Wolfgang Emmerich, 1999

Object-Orientation(Cont’d)

Wolfgang Emmerich

Page 13: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

13

25© Wolfgang Emmerich, 1999

Lecture Overview

■ Basic principles of object-orientation• objects• classes of object• encapsulation• inheritance• polymorphism

■ Object-orientation vs. structured methods

26© Wolfgang Emmerich, 1999

What’s object-orientation all about ?

■ Principles and techniques for systemmodelling which:• aim to produce a model of a system• provide notations and methods

■ Advantages for software development:• reduces the ‘semantic gap’ between reality

and models• makes system understanding easier• allows local modification to models

Page 14: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

14

27© Wolfgang Emmerich, 1999

An Object

■ An object is: "An abstraction ofsomething in a problem domain, reflectingthe capabilities of a system to keepinformation about it, interact with it, orboth” (Coad & Yourdon 91)

■ "An entity able to save a state(information) and which offers a numberof operations (behaviour) to eitherexamine or affect this state" (Jacobson92)

28© Wolfgang Emmerich, 1999

Objects & Abstraction

■ "An abstractiondenotes the essentialcharacteristics of

■ an object thatdistinguish it from allother kinds of objects

■ and thus providecrisply defiedconceptualboundaries,

■ relative toperspective of viewer" (B h 94)

Page 15: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

15

29© Wolfgang Emmerich, 1999

Sample Objects

■ From a “Food Manufacturing Company”■ Passive objects :

• one individual sack of lentils• invoice 63501 sent to A Farm, Lincolnshire

■ Active objects :• lorry "M235 BCM"• van "N683 CNM"

■ Human agents :• Richard Green• David Brown (Executive)• Hill, D (Truck driver)

■ Structure objects :• Marketing Department

30© Wolfgang Emmerich, 1999

Attributes and Associations

■ Any object has both attributes andassociations

■ Attributes characteristic features orproperties name / value pairs

■ Association any kind of link or connectionbetween one object and one or a set ofother objects

■ Characteristics private to an object bestrepresented as attributes

Page 16: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

16

31© Wolfgang Emmerich, 1999

Associations are Relationships

■ Two essential oppositions :■ aggregation vs reference relationships

• aggregation relationships where connectioncreates composite objects from simpleobjects

• reference relationships where connectiononly refers to another object

■ static vs dynamic relationships• static relationships, where coupling of

objects is stored over a long period of time,• dynamic relationships, which are established

by operations

32© Wolfgang Emmerich, 1999

Viewpoint of Association

■ View and purpose affect definition ofassoc.

■ Partition or division: Associationindicating new objects created by splittingother objects apart , e.g. A book ‘consistsof’ or ‘can be divided into’: title page,introduction, chapters, conclusion, index

■ Aggregation or amalgamation:Association indicating new objectscreated by adding other objects togethere.g Covers , bindin g, and end papers are

Page 17: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

17

33© Wolfgang Emmerich, 1999

AttributesName: GordonPosition: Junior LibrarianAge: 25Salary: 12,000......

Relations

Supervisor

OperationsLoan out books

Rename positionAmend salary

Timetable

Equipment

M

T

W

T

F

Structure and Behaviour of an Object

■ Gordon, Junior Librarian, as object

34© Wolfgang Emmerich, 1999

AttributesPrice: 2.95Weight: 1kg..........

RelationsOrder: 57891Delivery:57891ASupplier: A Farm

Operations

Is StoredIs SoldIs Delivered

One packet of herbal tea

AttributesAge: 45Sex: Male

Managing Director

OperationsDecide policies Attend meetings Manage Board meetings

Richard Green

Attributes

Staff: 50 peopleLocation: High St

Marketing Director Marketing Team

Market All ProductsChoose New ProductsDetermine Market Niches

Marketing Department

AttributesReg: M235 BCNWeight: 7.5 tonsFuel level: 40 litres

Driver Hill, DTrailor SSFG12

Operations

Deliveries Goods Repeat Until End Go To Destination Unload Goods EndRepeat Refuel....

Lorry M235 BCN

Relations

Relations

Relations

Operations

Behaviour and Structure

■ Example in a Food Company

Page 18: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

18

35© Wolfgang Emmerich, 1999

AttributesName: GordonPosition: Junior LibrarianAge: 25Salary: 12,000......

Relations

OperationsLoan out books

Rename positionAmend salary

Tim

etab

le

Equipm

ent

AttributesName: GordonPosition: Junior LibrarianAge: 25Salary: 12,000

......

Relations

Sup

ervi

sor

OperationsLoan out books

Rename positionAmend salary

Tim

etable Equipm

ent

Supervi

sor

Object Identity

■ Separate objects each have a uniqueobject identity

36© Wolfgang Emmerich, 1999

1

2

3

4

Dynamics of Objects

■ Dynamics are generated through stimulior messages passing between objects• Receipt of a stimulus cause operation by (or

in) the receiving object• Receipt of a stimulus can trigger sending of

another stimulus to other objects

Page 19: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

19

37© Wolfgang Emmerich, 1999

Encapsulation

■ “Behaviour and information areencapsulated in objects” (Jacobson 1992)

■ “Encapsulation is the process ofcompartmentalising the elements of anabstraction that constitute its structureand behaviour” (Booch 1995)• Only the 'interface' of an object is 'visible' to

other objects• Need, and can, only know operations on an

object, not how they work nor about othercharacteristics

• Necessary prerequisite for information hiding

38© Wolfgang Emmerich, 1999

Encapsulation (cont’d)

■ Encapsulation and abstraction arecomplementary concepts• Abstraction focuses on the observable

characteristics and behaviour of the object• Encapsulation focuses on the representation

derived from these characteristics

■ Encapsulation requires :• explicit division between abstractions• clear separation of their concerns

Page 20: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

20

39© Wolfgang Emmerich, 1999

Classes of Objects

■ Classes represent groups of objectswhich have the same behaviour andinformation structures.

■ Class is a kind of type, an ADT (but withdata), or an 'entity' (but with methods)

■ Classes are the same in analysis anddesign

■ “A class represents a template for severalobjects ...Objects of the same class havethe same definition both for theiroperations and for their information

40© Wolfgang Emmerich, 1999

AttributesPriceWeight.......

RelationsOrderDeliverySupplier

Is CreatedIs SoldIs Delivered

Product

AttributesRegistration No.WeightFuel

DriverTrailor

Operations

Deliveries Goods Repeat Until End Go To Destination Unload Goods EndRepeat Refuel....

Truck

AttributesAgeWeightSex

Role

Joins CompanyLeaves CompanyReviewedPromotedDemoted

Employee

AttributesPersonnel NumberLocation........

DirectorMarketing Team..........

Hire new staffDismiss new staff

Department

Relations

Relations

Relations

Operations Operations

Operations

Sample Classes

■ From a Food Company

Page 21: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

21

41© Wolfgang Emmerich, 1999

AttributesReg: M235 BCNWeight: 7.5 tonsFuel level: 40 litres

Driver: Hill, DTrailor: SSFG12

OperationsDeliveries Goods Repeat Until End Go To Destination Unload Goods EndRepeat Refuel....

Truck M235 BCN

Relations

Objects are Instances of Classes

■ Every object is aninstance of a single class

■ A class defines thepossible behaviours andthe information structureof all its object instances.

■ Different instances mayhave their operationsactivated in different waysand in differentsequences; hence theymay be in different states.

42© Wolfgang Emmerich, 1999

AttributesRegistration No.WeightFuel

DriverTrailor

Operations

Deliveries Goods Refuel

Truck

Relations

Create (Truck)

Delete (Truck)

Instantiation of objects

■ Instantiation of aclass generates anobject, an instance ofits class

■ Instantiationdemands a specificcreate operation inevery class

Page 22: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

22

43© Wolfgang Emmerich, 1999

Inheritance

■ Inheritence: a relationship betweendifferent classes with commoncharacteristics

■ “If class B inherits class A, then both theoperations and information structure inclass A will become part of class B”(Jacobsen 92)

■ Major benefits are simpler, clearerclasses, at higher levels of abstraction

OfficeAdmin

ClericalWorker

WarehouseAdmin

44© Wolfgang Emmerich, 1999

Generalisation & Specialisation

■ Generalisation - Creation of an 'ancestor'■ Specialisation - Creation of a 'descendant'

Employee

OfficeAdmin

Managing Director

ClericalWorker

WarehouseAdmin

Is_a

Page 23: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

23

45© Wolfgang Emmerich, 1999

Multiple Inheritance

■ One class inherits from two or moreexisting classes

■ Allows more complex class structures,but

■ less easil y understood

AdmittedPerson

TeachingAssistant

CourseLeader Student

46© Wolfgang Emmerich, 1999

(..A..)

(..A..)

?

(..A..)

Multiple Inheritance & Ambiguities

■ Name clashes : ■ Incorrect repeatedinheritance

(..A..)

?

Page 24: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

24

47© Wolfgang Emmerich, 1999

Polymorphism

■ System behaviour is defined by thedynamic behaviour of instances ofclasses

■ “Polymorphism means that the sender ofa stimulus does not need to know thereceiving instance's class. The receivinginstance can belong to an arbitary class”(Jacobsen 1992)

■ Polymorphism enables different instancesof different classes to be associated

■ A receiving instance interprets stimuli accordin g to its own class

48© Wolfgang Emmerich, 1999

Structured Methods

■ SSADM (Cutts 1987), SA (de Marco 1978),SADT (Ross 1977).

■ Existing structured methods treatseparately• functions (behaviour) and• data (information held)

■ Problems:• Difficulties with maintenance (because need

knowledge of data storage)• Division of knowledge (whereby “what” is

transformed into “how”)■ Instabilit y of functions

Page 25: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

25

49© Wolfgang Emmerich, 1999

Object-Oriented Methods

■ Better able to cope with changeItem Freq. Of ChangesObject from application LowLong-lived information structures LowPassive object’s attribute MediumSequence of behavior MediumInterface with outside world HighFunctionality High

■ OO focuses analysis on problem domain■ Promotes reuse■ Continuity of representation

50© Wolfgang Emmerich, 1999

Suggested object-oriented Methods

■ Coad & Yourdon (91) for OOA■ Booch (94) also for OOA■ Jackson (83) for system design■ Jacobson (92) OOSE■ Approach of this course based on

Jacobson because employs ‘use cases’throughout• essential user role• focus on domain• integration in process

■ All likely to be superseeded by ‘retreads’employing the UML

Page 26: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

26

51© Wolfgang Emmerich, 1999

Drawbacks of OO

■ Large scale reuse not yet achieved

■ Few available reusable libraries

■ Managing reusable libraries is a problem

■ Extensive retraining before pervasive

52© Wolfgang Emmerich, 1999

Summary

■ Basic concepts:• object: entity combining essential

characteristics abstracted from a domain• class: expression of objects’ common

characteristics• encapsulation: combination of attributes &

operations in a single self-contained object• inheritance: relationship between super-class

and sub-class defining levels of commonality• polymorphism: facility allowing stimuli to

ignore class of receiving object

Page 27: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

27

53© Wolfgang Emmerich, 1999

Summary (Cont’d)

■ Application of concepts enables:• object identification• object modelling• behaviour modelling

54© Wolfgang Emmerich, 1999

D50: Advances in Software Engineering

Requirements Model

Wolfgang Emmerich

Page 28: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

28

55© Wolfgang Emmerich, 1999

Lecture Overview

■ Object-Oriented Software Engineering (OOSE)from Jacobson et al.

■ The basics of ‘a use case driven approach’■ Development of a Requirements Model:

• actors• use cases• interface descriptions• problem domain objects

■ Relevant notations from the UML (UnifiedModeling Language)

56© Wolfgang Emmerich, 1999

OOSE Background

■ Originated in Sweden■ "Object-Oriented Software Engineering -

A Use Case Driven Approach" by IvarJacobson, Magnus Christerson, PatrikJonsson & Gunnar Overgaard, Addison-Wesley , 1992

■ Pragmatic method based on experience■ Popular and successful■ Complete method

Page 29: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

29

57© Wolfgang Emmerich, 1999

What comprises a Method?

■ Method described via• syntax (how it looks)• semantics (what it means)• pragmatics (heuristics, rules of thumb for

use)

58© Wolfgang Emmerich, 1999

Requirements Model:captures functionalrequirements fromuser perspective

Seamless, incremental transition between stages and models, iterations possible

Analysis Model:maintainable withlogical structure;implementation-

independent

ANALYSIS CONSTRUCTION TESTING

Design Model:impose implementationconstraints on analysis

model

Implementation Model:system code written

from the design model

Test Model:documentationand test results

System Dev. as Building Models

■ 3 stages and 5 models

Page 30: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

30

59© Wolfgang Emmerich, 1999

■ Primary objectives• to determine what the system must do• to embed the software system in its

environment■ Two concerns

• to get the right thing• to get the thing right (now and for future)

■ Products• Requirements Model• Analysis Model

customer

requirements

domain object modeluse case model

interfaces

Requirements Model

Analysis Stage

60© Wolfgang Emmerich, 1999

Producing A Requirements Model

■ Inputs1 Derive possible use cases2 Discriminate between possible use cases3 Generate use case desciptions4 Identify associations between use cases5 Refine & complete use cases & use case

model6 Describe and test user interfaces7 Describe system interfaces8 Identification of problem domain objects9 Check incorporation of requirements

■ Outputs■ Notations

Page 31: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

31

61© Wolfgang Emmerich, 1999

Requirements Model: Input & Output

■ Inputs :• User requirements specifications [multi

media]• Documentation of existing systems, practices

etc. that are to be followed [text, graphic]• Exchanges between developers and users

and specifiers [m m]■ Outputs :

• use case model [graphic]• concise descriptions of use cases [text]• user interface descriptions [text ...

prototypes]• system interfaces [protocols]• problem domain object list (names attrib )

62© Wolfgang Emmerich, 1999

Requirements Model: Notations

■ Notations introduced :• use case diagram (system box, ellipses,

names, actor icons, actor/case links, <uses>and <extends> associations)

• association (<extends>, <uses>)• use case descriptions

Page 32: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

32

63© Wolfgang Emmerich, 1999

Multi-purpose recycling machine

Machine must:- receive & check items for customers,- print out receipt for items received,- print total received items for operator,- change system information,- signal alarm when problems arise.

Recycle Machine

Cans

Bottles

Crates

Receipt

Requirements Example

64© Wolfgang Emmerich, 1999

Actors

■ An actor is:• anything external to the system, human or

otherwise• a user type or category

■ A user doing something is an occurrenceof such a type

■ A single user can instantiate severaldifferent actor types

■ Actors come in two kinds:• primary actors, using system regularly• secondary actors, enabling primary actors

Page 33: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

33

65© Wolfgang Emmerich, 1999

instantiated as instantiated as

actor use caseinitiates

user scenarioinitiates

A Use Case

■ A use case• constitutes complete course of events

initiated by actor• defines interaction between actor and system• is a member of the set of all use cases which

■ Use cases together define all existingways of using the system

66© Wolfgang Emmerich, 1999

Example Use Case

■ Returning items is started by Customerwhen she wants to return cans, bottles orcrates. With each item that the Customerplaces in the recycling machine, thesystem will increase the received numberof items from Customer as well as thedaily total of this particular type. WhenCustomer has deposited all her items,she will press a receipt button to get areceipt on which returned items havebeen printed, as well as the total returnsum.

Page 34: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

34

67© Wolfgang Emmerich, 1999

Generate report

Operator

Customer

Recycling Machine

Change item information

Returning item

Use Case Model

■ A use case model• presents a collection of use cases• characterise behaviour of whole system, plus

external actors

68© Wolfgang Emmerich, 1999

Identifying Use Cases

■ Consider situation,■ Identify actors,■ Read specification,■ Identify main tasks,■ Identify system information,■ Identify outside changes,■ Check information for actors,■ Draft initial use cases [text]■ Identify system boundary,■ Draft initial use case model [graphic]

Page 35: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

35

69© Wolfgang Emmerich, 1999

When is a Use Case .... ?

■ Discrimination between possible usecases• Estimate frequency of use,• Examine degree of difference between cases• Distinguish between 'basic' and 'alternative'

courses of events• Create new use cases where necessary

70© Wolfgang Emmerich, 1999

Elaborated Example

BASIC - When the Customer returns a deposit item, it ismeasured by the system. The measurements are used todetermine what kind of can, bottle or crate has bedeposited. If accepted, the Customer total is incremented,as is the daily total for that specific item type.ALTERNATIVE - If the item is not accepted, 'NOT VALID'is highlighted on the panel.BASIC - When Customer presses the receipt button, theprinter prints the date. The customer total is calculatedand the following information printed on the receipt foreach item type: name, number returned, deposit value,total for this type. Finally the sum that the Customershould receive is printed on the receipt.

Page 36: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

36

71© Wolfgang Emmerich, 1999

Operator’s interface

Change bottle dataType:Size:Value:

User Interface Descriptions

■ Describe user interfaces■ Test on potential users,■ if necessary using■ simulations or prototypes

72© Wolfgang Emmerich, 1999

Problem Domain Objects

■ Object in specification have directcounterpart in the applicationenvironment

■ System knowledge obligatory■ Refinement in stages :

• Object noun →• Logical attributes →• Static associations →• Inheritance →• Dynamic associations →• Operations

Page 37: Object-Orientation - UCL Computer Science · Basic principles of object-orientation • objects • classes of object • encapsulation • inheritance • polymorphism

37

73© Wolfgang Emmerich, 1999

Object Examples

Object name Attribute characteristic/information :type

Deposit item name: string, total: integer, value: EuroCan width: cm, height: cmBottle width: cm, height: cm, bottom: cmCrate width: cm, height: cm, lenght: cmReceipt total cans: int, total bottles: int, ...Customer panel receipt button: buttonOperator panel bottle data: cm, ...

74© Wolfgang Emmerich, 1999

Summary

■ System development as model building■ Requirements model “to get the right

thing”■ System use in context via the use case

model■ User interface descriptions■ Problem domain objects as prelude to

class diagram