Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE -...

42
Software Engineering Object-Oriented Analysis 1 Software Engineering 2004-2005 Marco Scotto ([email protected])

Transcript of Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE -...

Page 1: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

Software Engineering

Object-Oriented Analysis 1

Software Engineering2004-2005

Marco Scotto ([email protected])

Page 2: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

2Software Engineering

Content

Introduction Finding the objectsCRC methodReviewing the analysis

Page 3: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

3Software Engineering

Traditional structured analysis

Focus is on information flow and on functional decompositionStatic model of data Languages: Fortran, PL/I, Pascal and C. They are based on functions and procedures operating on common data.OO approach: put together the data and the functions operating on the data (often called methods)

modularity and information hiding

Page 4: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

4Software Engineering

Introduction to OO approach OO approach: combining data and functions • Achieving a degree of modularity and info hiding

Same underlying (OO) model behind all phases• OO analysis, OO design, OO programming

Dealing with problem domain (the real world)• Traditional system analysis: with data flow

diagrams• OO analysis: with use cases and user stories

UML diagrams for OOA• Use case diagrams (UCD); Class diagrams (CD);

State diagrams

Page 5: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

5Software Engineering

The crumble of the walls

Real world (problem domain)

System Analysis(DFD, structuredanalysis…)

System Design and coding (Subsystems, procedural languages…)

Traditional approach

Real world (problem domain)

OO Analysis (OO model: classes, methods, inheritance…)

OOD & OOP (OO model: classes, methods, inheritance; OOPLs…)

Object-oriented approach

Page 6: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

6Software Engineering

The modeling cycle

Extractingthe objects

Coding

Exploring andunderstanding

Page 7: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

7Software Engineering

Modeling the system

Now we have:• A description of the requirements of the

customer (User stories)• A general description of the system to

develop (Metaphor)

We need now to shape the system:• Formalizing the functionalities• Identifying which part of the system is in

charge of what functionality

Page 8: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

8Software Engineering

Our reference coding paradigm

We use an Object Oriented paradigm as implemented in the Java programming languageThe key computational entities are called “Objects”The object are characterized by:• Who they are –ontology• What they do –behavior

The objects belong to classes

Page 9: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

9Software Engineering

Why is OO popular?

The hope that it will increase productivityNatural way of structuring the world• Objects• Messages• Responsibility

Page 10: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

10Software Engineering

What is object-oriented software development?

A way to view the world of the applicationA way to describe a model of the applicationA comprehensive methodology that • allows to develop a software system • uses similar concepts within the whole

development process

Page 11: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

11Software Engineering

Object oriented system development

Means to achieve high quality• Information Hiding• Abstraction• Modularization• Reuse

An object oriented approach - more or less - forces the software developer to apply these concepts

Page 12: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

12Software Engineering

OO methodologies

Late 80’s early 90: several OO methodologies developed• different notations• different processes

Main approaches• Booch• Rumbaugh• Jacobson (OMT)• UML

Page 13: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

13Software Engineering

Key Conceptsclasses and class hierarchiesclasses and class hierarchies• attributes• methods• inheritance• relations with other classes

objects: instances of classesobjects: instances of classes• attributes with assigned values

• instantiated relations

messages and methods to respond to a messages and methods to respond to a messagemessage

Page 14: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

14Software Engineering

ExampleNancy is a girl, with a sequence of attributes that are inherited from the fact that a girl is a Person• We identify that specific girl with the sequence of

attributes: Nancy; 11 10th Av.,Washington, DC; 21; XCW553245

The 550 Maranello is an instance of a Ferrari, with a sequence of attributes that are inherited from Car• We identify that specific Ferrari with the sequence

of attributes: Ferrari; 550 Maranello; I LOVE F; Red

While inheriting, some attributes can become fixed

Page 15: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

15Software Engineering

An OO ModelAnimal

Dog Person

Pyr GuyGirl

Name; Address;Age; Lic. #

Means of Transportation

Plane

Car

PorscheFerrari

Maker; Model;ID Number;Color

Drives

is-ais-a

is-a is-a is-a

is-a is-a

is-a is-a

has

Nancy; 11 10th Av.,Washington, DC; 21;XCW553245

has

Ferrari; 550 Maranello;I LOVE F; Red

Is instance of

Is instance of

Page 16: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

16Software Engineering

Summary of classes and objectsClasses are organized in:• Hierarchies• Taxonomies (with various kind of

relationships)

Objects are instances of and belong to one class:• In general, they cannot change the class at

run time• References may be assigned to objects of the

references’ classes or to descendants• Objects know who they are

Page 17: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

17Software Engineering

Inheritance is NOT Instantiation

Animal

Dog Person

Pyr GuyGirl

is-a

Chiuaua

is-a

is-a is-a is-ais-aI Love

Pyrs!!!!

I refer to the class of Pyrs that is derived from the class of Dogs

I refer to Pluto, an instance of class Dog - I do not know and I do not care

which sub-class of dog Pluto belongs to

I LoveI LovePluto!!!Pluto!!!

Page 18: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

18Software Engineering

Content

Introduction Finding the objectsCRC methodReviewing the analysis

Page 19: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

19Software Engineering

Finding the objects

Starting point: requirements elicited by the customer (requirement document)• Use Cases (in UML notation)• User stories in an agile environment

Key problem in OOA: finding the “right” objects• highly dependent on the domain• for example: even a single object performing

all system functionalities could work traditional programming

Page 20: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

20Software Engineering

Noun extractionA common technique to find relevant objectsParse specification documents, look for nounsSteps to be followed:• List nouns found, including composite names and names

with adjectives• Analyze nouns found

Consider composite names and names with adjectivesPay attention to passive sentences and hidden entitiesLook for synonyms

• Discard irrelevant names• Categorize names found

Page 21: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

21Software Engineering

Object categories (1/2)Category Description Examples Typical

responsibilities

Actor Person or organization with a role in system

Person, Organization, Agency, Association, Department, Firm

Has name, identification number, address, age, SSN.

Role of the actor

How actors act in the system

Operator, customer, supplier, employee, manager, student

Has name, identification number, state, password.

Location Places or locations containing other objects

Airport, Building, Garage, Plant, Harbour, Room, Shop, Site, Store

Has name, address.Knows and manages the objects contained

Tangible Thing Machinery and tangible things of the problem domain

Airplane, Car, Container, Lathe, Pallet, Ship, Truck

Has tag, location, description, state.Executes and records its activity

Page 22: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

22Software Engineering

Object categories (2/2)Category Description Examples Typical

responsibilities

Abstract Thing

Abstract, but actual, things of the problem domain

Account, Course, Degree, Paragraph, Plan, Program

Has identifier, state.Executes and records its activity

Device A physical or logical device, or a system connected to our system

Actuator, Internet, LAN, Light, Radar, Sensor

Has identifier.Manages I/O from/to the device or system

Event, Transaction

Events that the system must manage and store. A transaction is an event or a time interval

Authorization, Deposit, Contract, Examination, Graduation, Registration

Has identifier, date, time, responsibility.Holds and manages transaction items

Transaction item

Specific items making up the transaction

Invoice Line, Contract Paragraph

Has state.

Container Objects containing (sets of) other objects

Airplane, Coach, Chain Stores, Container, Faculty, Ship, Team

Knows and manages the objects contained

Page 23: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

23Software Engineering

Simple example: subway simulation system

Three user stories derived from a subway simulation system.

The system manages a subway composed of a line, with stations and tracks. The line is composed by two tracks, one in the leftdirection and the other in the right. Along the subway line, there is a sequence of stations where the trains stop. Each track is composed by a sequence of track sections. These can be line sections, connecting two stations, or station sections. A line section is followed by a station section, that is in turn followed by a line section, and so on. Line sections are outside the stations, and end with a protection signal controlling the access to the subsequent station section. Station sections are inside the stations, and end with a start signal controlling the access to the subsequent line section.Both tracks begin and end with a interchange section, situated in terminal stations. At the end of its course, a train enters the interchange section (if there is no other train on it), change direction and then comes out of the interchange, entering the other track.

Page 24: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

24Software Engineering

Simple example: finding the nounsThree user stories derived from a subway simulation system.

The system manages a subway composed of a line, with stations and tracks. The line is composed by two tracks, one in the left direction and the other in the right. Along the subway line, there is a sequence of stations where the trains stop. Each track is composed by a sequence of track sections. These can be line sections, connecting two stations, or station sections. A line section is followed by a station section, that is in turn followed by a line section, and so on. Line sections are outside the stations, and end with a protection signal controlling the access to the subsequent station section. Station sectionsare inside the stations, and end with a start signal controlling the access to the subsequent line section.Both tracks begin and end with a interchange section, situated in terminal stations. At the end of its course, a train enters the interchange section (if there is no other train on it), change direction and then comes out of the interchange, entering the other track.

Page 25: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

25Software Engineering

Simple example: nouns extraction

systemsubwaylinestationtrackdirectionsubway line

sequence traintrack sectionline sectionstation sectionprotection signal

start signalaccess start signalinterchangesectionterminal stationcourse

Page 26: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

26Software Engineering

Simple example: some relevant objects

system A generic term of the item that will be developed, not related to a specific class.

subway, line, subway line

These three terms denote the same object in our problem domain. In fact, the system to be simulated is composed by only one line. We will call this class: “Line”.

station Clearly, a relevant object of our system. We will call this class: “Station”.

track A line is composed of two tracks, so this object seems part of the problem domain. We will call this class: “Track”.

track section A track is composed of track sections. We will call this class: “TrackSection”.

Interchange section A kind of track section. We will call this class: “InterchangeSection”.

Page 27: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

27Software Engineering

Content

Introduction Finding the objectsCRC methodReviewing the analysis

Page 28: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

28Software Engineering

CRC methodC: Class• Finds the classes of objects constituting the

systemR: Responsibility• Defines responsibility of the classes

C: Collaboration• Finds collaborations (exchange of info) needed

among classes to fulfill the responsibilitiesDistinction to be made• Classes for OOA• Objects for working systems

Page 29: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

29Software Engineering

CRC Cards: index cards

Class NameMain Responsibility

Responsibilities Collaborators

. . . . . .

4 X 6(or 3 X 5)Index card

Some also suggest writing down the classes properties (what the class must know about itself –knowledge responsibility) on the back of the card

Page 30: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

30Software Engineering

CRC session (1/2)Finding and assigning responsibilitiesCRC method uses index cards• Name and short description of the class (Class)• Functionalities (Responsibility)• List of other cooperating classes (Collaboration)

CRC session• Starts with brainstorming meeting• Should be performed with actual index cards• Active discussion between developers and customers• Delays actual specification (reducing irreversibility)

Page 31: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

31Software Engineering

CRC session (2/2)Naming is critical• A name familiar to customer denoting a single object

of the class

Responsibility • Hold info: achieved with one or more attributes• Perform computation: achieved with one or more

methods

Criteria in assigning responsibilities• System behaviour kept balanced and distributed• No duplicate info• Assignment to the highest possible class in the

inheritance hierarchy

Page 32: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

32Software Engineering

Collaboration Can a class fulfill its responsibilities alone?One-way relationship• Two classes mutually need each other two

different collaborationsStrongly indicated by the following relationships• Has-knowledge-of• Depends-on (changes with)• Is-part-of (composite)

container (is-part-of) aggregation does not always indicate collaboration

Collaborations are written on CRC card

Page 33: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

33Software Engineering

Assessing the CRC model (1/2)Criteria for scrutinizing the necessity of objects• Information to be remembered by system• Needed behaviour for the system• Significance of responsibilities • Collaboration(s) with other classes• Is there only one object in the class?• Applicability of responsibility

Root class and non-leaf classes can be abstract• Has no instances• Group responsibilities common to all the subclasses

Page 34: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

34Software Engineering

Assessing the CRC model (2/2)Two options for using CRC model:• Using CRC model to define data structure and

behaviour of classes, then developing OOA model

• Writing code with CRC model as a guide, using OOPL

Latter options used in eXtreme Programming• Effective when test-first programming and

continuous refactoring are used

Page 35: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

35Software Engineering

Simple example: CRC cards for the subway simulation system

InterchangeSectionA special track section, situated in terminal stations and with no direction. It is connected with two opposite station sections at the same end, and has no connection in the other end. A train can enter this section from a station section, change direction and exit the section from the same end, to another track section.Responsibilities of InterchangeSection:• Accepts trains in a direction and knows how to make

them change direction.• Knows the two station sections connected to it at one of

its ends.• Knows its terminal station.

Page 36: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

36Software Engineering

Simple example: CRC Card for classInterchangeSection

InterchangeSection subclass of: StationSection

A special track section, situated in terminal stations and with no direction. It is connected with two opposite station sections at the same end, and has no connection in the other end. A train can enter this section from a station section, change direction and exit the section from the same end, to another track section.Responsibilities:•Accepts trains in a direction and knows how to make them change direction.•Knows the two station sections connected to it at one of its ends.•Knows its terminal station.

Collaborations:TrainStationSectionTerminalStation

Page 37: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

37Software Engineering

Proposed Exercise – Build US, Metaphor, and the CRC Cards

We just won a bid to design a custom coffee vending machine for the employees of XX WorksArnold, the owner of XX Works, wants his own custom design –no standard vending machine for him!However, Arnold is a cheapskate. He wants a simple machineAll he wants is a machine that serves coffee for 35 cents, with or without sugar and creamerOf course, he wants us to put the machine together quickly and for little cost

Page 38: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

38Software Engineering

Arnold changes his mind

The situation gets more complex…After five machines are installed and have been operating for a while, Arnold comes along and says, “I would like to add bouillon, at twenty-five cents”. Change the design.

Page 39: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

39Software Engineering

ContentIntroductionFinding the objectsCRC methodReviewing the analysis

Page 40: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

40Software Engineering

6 Tests for Evaluating an Analysis1. Data Connectedness

• Can you traverse the network of collaborations to gather all the information you need to deliver the services?

2. Abstraction• Does the name of the object convey its

abstractions? Does the abstraction have a natural meaning and use in the domain?

3. Responsibility Alignment• Do the name, main responsibility

statement data and functions align?

Page 41: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

41Software Engineering

6 Tests for Evaluating an Analysis (cont.)

4. Data Variations• Does the design naturally handle all the

sorts and shapes of data it will encounter?

5. Evolution• How many classes need to change for a

“normal system change?”

6. Communication Patterns• Are there oddly shaped run-time

communication patterns (e.g. cycles)?

Page 42: Object-Oriented Analysis 1 - Free University of Bozen …pro.unibz.it/staff/mscotto/SE/SE - Object-oriented Analysis 1.pdf · Software Engineering Object-Oriented Analysis 1 Software

42Software Engineering

Revising the resulting model

We can now find a way to organize all the classes and objects in the system, according to the metaphor we have usedWe can define identify some “pre-cooked”styles