analysis: object modeling - technische universität münchen · do uml associations have direction?...
TRANSCRIPT
Con
quer
ing
Com
plex
and
Cha
ngin
g Sy
stem
sO
bjec
t-O
rien
ted
Soft
war
e E
ngin
eeri
ngChapter 5, Analysis:Object Modeling
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 2
Exercise 2.6
Draw a sequence diagram for the warehouseOnFire scenario (asdescribed in the requirements elicitation lecture).
Include the objects bob, alice, john, system, and instances of otherclasses you may need.
Draw only the first five message sends.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 3
Solutions to exercise 2.6
:FRIEND
:EmergencyFormreportEmergency()
new EmergencyForm()
specifyIncident()
notifyDispatcher()
alice john
requestResource(fireTruck)
commit()
bob
Initiating actor shouldbe on this side.
Dispatcher should beon this sideAll objects involved in
this scenario are instances.This is how an objectcreation looks like.
Note: this exercise can have many other acceptable solutions.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 4
Exercise 2.7
Draw a sequence diagram for the ReportIncident use case (asdescribed in the requirements elicitation lecture).
Make sure it is consistent with the sequence diagram of the previousexercise.
Draw only the first five message sends.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 5
Sample solution to exercise 2.7
FRIEND
EmergencyFormreportEmergency()
new EmergencyForm()
specifyIncident()
notifyDispatcher()
FieldOfficer Dispatcher
*requestResource()
commit()
This is a use case,hence, we are dealing
with classes.
Class and operationnames should be the
same as in the previousdiagram.
This is how an iterationis specified.
Note: this exercise can have many other acceptable solutions, as before.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 6
Outline
♦ From use cases to objects
♦ Object modeling
♦ Class vs instance diagrams
♦ Attributes
♦ Operations and methods
♦ Links and associations
♦ Examples of associations
♦ Two special associationsw Aggregationw Inheritance
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 7
From Use Cases to Objects
Level 1 Use Case
Level 2 Use Cases
Level 3 Use Cases
Operations
ParticipatingObjects
Le vel 2
Level 1
Le vel 2
Le vel 3 Le vel 3
Le vel 4 Le vel 4
Le vel 3
A B
UserTasks
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 8
From Use Cases to Objects: Why FunctionalDecomposition is not Enough
Scenarios
Level 1 Use Cases
Level 2 Use Cases
Operations
ParticipatingObjects
Le vel 2
Level 1
Le vel 2
Le vel 3 Le vel 3
Le vel 4 Le vel 4
Le vel 3
A B
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 9
How do we describe complex systems (Natural Systems, SocialSystems, Artificial Systems)?
Epistemology
Knowledge about Causality(Dynamic Model)
Describes our knowledge about the system
Knowledge about Functionality(Functional model)
Knowledge about Relationships(Object model)
NeuralNetworks
DataFlow Diagrams(SA/SD)
Scenarios/Use Cases(Jacobson)
FormalSpecifications
(Liskov)
State Diagrams(Harel)
Petri Nets(Petri)Inheritance
Frames,SemanticNetworks (Minsky)
Uncertain KnowledgeFuzzy Sets (Zadeh)
Data Relationship(E/R Modeling, Chen)
Hierarchical Database
Model (IMS)
NetworkDatabase
Model(CODASYL)
RelationalDatabase Model
(Codd)
Fuzzy Frames(Graham)
Class Diagrams(“E/R + Inheritance”,
Rumbaugh)
SequenceDiagrams
Activity Diagrams
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 10
Definition: Object Modeling
♦ Main goal: Find the important abstractions
♦ What happens if we find the wrong abstractions?w Iterate and correct the model
♦ Steps during object modelingw 1. Class identification
t Based on the fundamental assumption that we can find abstractions
w 2. Find the attributesw 3. Find the methods
w 4. Find the associations between classes
♦ Order of stepsw Goal: get the desired abstractions
w Order of steps secondary, only a heuristicw Iteration is important
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 11
Class Identification
♦ Identify the boundaries of the system
♦ Identify the important entities in the system
♦ Class identification is crucial to object-oriented modeling
♦ Basic assumption:w 1. We can find the classes for a new software system (Forward
Engineering)
w 2. We can identify the classes in an existing system (ReverseEngineering)
♦ Why can we do this?w Philosophy, science, experimental evidence
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 12
Class identification is an ancient problem
♦ Objects are not just found by taking a picture of a scene or domain
♦ The application domain has to be analyzed.
♦ Depending on the purpose of the system different objects might befoundw How can we identify the purpose of a system?
w Scenarios and use cases
♦ Another important problem: Define system boundary.w What object is inside, what object is outside?
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 13
What is This?
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 14
Pieces of an Object Model
♦ Classes
♦ Associations (Relations)w Part of- Hierarchy (Aggregation)w Kind of-Hierarchy (Generalization)
♦ Attributesw Detection of attributesw Application specific
w Attributes in one system can be classes in another systemw Turning attributes to classes
♦ Methodsw Detection of methodsw Generic methods: General world knowledge, design patterns
w Domain Methods: Dynamic model, Functional model
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 15
Object vs Class
♦ Object (instance): Exactly one thingw The lecture on November 2 on Software Engineering from 14:30 -16:00
♦ A class describes a group of objects with similar propertiesw IETM, Author, Corrosion, Work order
♦ Object diagram: A graphic notation for modeling objects, classes andtheir relationships ("associations"):w Class diagram: Template for describing many instances of data. Useful for
taxonomies, patters, schemata...w Instance diagram: A particular set of objects relating to each other. Useful
for discussing scenarios, test cases and examples
♦ Together-J: CASE Tool for building object diagrams, in particularclass diagramsw Tutorial on November 10
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 16
UML: Class and Instance Diagrams
Inspector
joe:Inspector
mary:Inspector
anonymous:Inspector
Class Diagram
Instance Diagram
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 17
Attributes and Values
name:stringage: integer
Inspector
name = “Joe”age = 24
joe:Inspector
name = “Mary”age = 18
mary: Inspector
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 18
Operation, Signature or Method? What when?
♦ Operation: A function ortransformation applied to objects in aclass. All objects in a class share thesame operations (Analysis Phase)
♦ Signature: Number & types ofarguments, type of result value. Allmethods of a class have the samesignature (Object Design Phase)
♦ Method: Implementation of anoperation for a class (ImplementationPhase)
Polymorphic operation: The sameoperation applies to many differentclasses.
Workorder
File_name: StringSize_in_bytes: integerLast_update: dateStickies: array[max]
print()delete()open()close()write()read()
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 19
Links and Associations
♦ Links and associations establish relationships among objects andclasses.
♦ Link:w A connection between two object instances. A link is like a tuple.
w A link is an instance of an association
♦ Association:w Basically a bidirectional mapping.
w One-to-one, many-to-one, one-to-many,w An association describes a set of links like a class describes a set of objects.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 20
1-to-1 and 1-to-many Associations
Has-capital
One-to-one association
One-to-many association
City
name:String
Workorder
schedule()
StickyNote
x: Integery: Integerz: Integer
*
Country
name:String
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 21
Object Instance Diagram
Example for 1-to-many
:Sticky
x,y,z=(-1,0,5)
:WorkOrder :Sticky
x,y,z=(1,10,1)
:Sticky
x,y,z=(10,1,2)
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 22
Many-to-Many Associations
Work on **Mechanics Plane
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 23
Roles in Associations
♦ Client Role:w An object that can operate upon other objects but that is never operated
upon by other objects.
♦ Server Role:w An object that never operates upon other objects. It is only operated upon
by other objects.
♦ Agent Role:w An object that can both operate upon other objects and be operated upon
by other objects. An agent is usually created to do some work on behalf ofan actor or another agent.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 24
Do UML associations have direction?w A association between two classes is by default a bi-directional mapping.
t Class A can access class B and class B can access class A
t Both classes play the agent role.
A B
If you want to to make A a client, and B a server, you can make theassociation unidirectional. The arrowhead points to the serverrole:
Class A ( the “client”) accesses class B (“the server”). B is also callednavigable
A Baccesses
Name DirectionName of association
Association Direction
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 25
Aggregation
♦ Models "part of" hierarchy
♦ Useful for modeling the breakdown of a product into its componentparts (sometimes called bills of materials (BOM) by manufacturers)
♦ UML notation: Like an association but with a small diamondindicating the assembly end of the relationship.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 26
weight
Automobile
serial numberyearmanufacturermodelcolor
drivepurchase
Aggregation
Engine
horsepowervolume
onoff
3,4,5
Wheel
diameternumber of bolts
2,4
Door
openclose
Battery
ampsvolts
chargedischarge
*
Brakelight
onoff
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 27
Inheritance
♦ Models "kind of" hierarchy
♦ Powerful notation for sharing similarities among classes whilepreserving their differences
♦ UML Notation: An arrow with a triangleCell
MuscleCellBloodCell NerveCell
StriateSmoothRed White PyramidalCortical
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 28
Aggregation vs Inheritance
♦ Both associations describe trees (hierarchies)wAggregation tree describes a-part-of relationships (also called
and-relationship)w Inheritance tree describes "kind-of" relationships (also called
or-relationship)
♦ Aggregation relates instances (involves two or moredifferent objects)
♦ Inheritance relates classes (a way to structure thedescription of a single object)
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 29
Other Associations
♦ Uses:w A subsystem uses another subsystem (System Design)
♦ Contains:w Sometimes called “spatial aggregation”
w ... contains ...w Example: A UML package contains another UML package
♦ Parent/child relationship:w ... is father of ...w ... is mother of ...
♦ Seniority:w ... is older than ...w ... is more experienced than ...
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 30
Odds and Ends
♦ Hoererschein for the book:w Participating Bookstores: If you say you are taking this class, you get 10%
off at:t Buchladen am Obelisk (Barerstrasse),
t Kanzler (Gabelsbergerstrasse),
t Lachner (Theresienstrasse)
♦ Solution to last exercise
♦ Finding a superclass
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 31
Object Types11/2/00
♦ Entity Objectsw Represent the persistent information tracked by the system (Application
domain objects, “Business objects”)
♦ Boundary Objectsw Represent the interaction between the user and the system
♦ Control Objects:w Represent the control tasks performed by the system
♦ Having three types of objects leads to models that are more resilientto change.w The boundary of a system changes more likely than the control
w The control of the system change more likely than the application domain
♦ Object types originated in Smalltalk:w Model, View, Controller (MVC) => Observer Pattern
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 32
Example: 2BWatch Objects
♦ UML provides several mechanisms to extend the language
♦ UML provides the stereotype mechanism to present new modelingelements
<<entity>>Year
<<entity>>Month
<<entity>>Day
<<control>>ChangeDateControl
<<boundary>>LCDDisplayBoundary
<<boundary>>ButtonBoundary
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 33
Roles
♦ A role name is the name that uniquely identifies one end of anassociation.
♦ A role name is written next to the association line near the class thatplays the role.
♦ When do you use role names?w Necessary for associations between two objects of the same classw Also useful to distinguish between two associations between the same pair
of classes
♦ When do you not use role names?w If there is only a single association between a pair of distinct classes, the
names of the classes serve as good role names
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 34
Example of Role
Problem Statement : A person assumes the role of repairer with respect to another person, who assumes the role of inspector with respect to the first person.
Person* Creates Workorders
inspector
repairperson* Creates Workorders
Person Person
Person
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 35
Qualification
♦ The qualifier improves the information about the multiplicity of theassociation between the classes.
♦ It is used for reducing 1-to-many multiplicity to 1-1 multiplicity
With qualification: A directory has many files, each with a unique name
Without qualification: A directory has many files. A file belongs only to onedirectory.
Directory Filefilename
DirectoryFile
filename
1 *
0..11
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 36
Example
Problem Statement : A stock exchange lists many companies. However , a stock exchange lists only one company with a given ticker symbol. A company may be listed on many stock exchanges, possibly with different ticker symbols. Find company with ticker symbol AAPL, DCX.
StockExchangeCompany
tickerSym
* *lists
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 37
StockExchangeCompany
tickerSym
* *
Use of Qualification reduces multiplicity
StockExchange CompanytickerSym 0..11
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 38
How do you find classes?
♦ Learn about problem domain: Observe your client
♦ Apply general world knowledge and intuition
♦ Take the flow of events and find participating objects in use cases
♦ Apply design patterns
♦ Try to establish a taxonomy
♦ Do a textual analysis of scenario or flow of events (Abbott TextualAnalysis, 1983)
♦ Nouns are good candidates for classes
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 39
Mapping parts of speech to object model components[Abbot 1983]
Part of speech Model component Example
Proper noun object Jim Smith
Improper noun class Toy, doll
Doing verb method Buy, recommend
being verb inheritance is-a (kind-of)
having verb aggregation has an
modal verb constraint must be
adjective attribute 3 years old
transitive verb method enter
intransitive verb method (event) depends on
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 40
Example: Scenario from Problem Statement
♦ Jim Smith enters a store with the intention of buying a toy for his 3year old child.
♦ Help must be available within less than one minute.
♦ The store owner gives advice to the customer. The advice depends onthe age range of the child and the attributes of the toy.
♦ Jim selects a dangerous toy which is unsuitable for the child.
♦ The store owner recommends a more yellow doll.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 41
Object Modeling in Practice: Class Identification
Foo
Balance
CustomerId
Deposit()Withdraw()GetBalance()
Class Identification: Name of Class, Attributes and Methods
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 42
Object Modeling in Practice:Encourage Brainstorming
Foo
Balance
CustomerId
Deposit()Withdraw()GetBalance()
Account
Balance
CustomerId
Deposit()Withdraw()GetBalance()
Naming is important!
“Dada”
Balance
CustomerId
Deposit()Withdraw()GetBalance()
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 43
Object Modeling in Practice
Account
Balance
Deposit()Withdraw()GetBalance()
Customer
Name
CustomerId
Find New Objects
CustomerIdAccountId
Iterate on Names, Attributes and Methods
Bank
Name
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 44
Object Modeling in Practice: A Banking System
Account
Balance
Deposit()Withdraw()GetBalance()
Customer
Name
CustomerId
CustomerIdAccountIdAccountIdBank
Name
Find New Objects
Iterate on Names, Attributes and Methods
Find Associations between Objects
Has
Label the assocations
Determine the multiplicity of the assocations
*
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 45
Object Modeling in Practice: Categorize!
SavingsAccount
Withdraw()
CheckingAccount
Withdraw()
MortgageAccount
Withdraw()
Customer
Name
CustomerId
Account
Amount
Deposit()Withdraw()GetBalance()
CustomerIdAccountIdAccountId
Bank
Name Has**
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 46
Avoid Ravioli Models
Customer
Name
CustomerId
Account
Amount
Deposit()Withdraw()GetBalance()
CustomerIdAccountIdAccountId
Bank
Name Has**
Don’t put too many classes into the same package:7+-2 (or even 5+-2)
Don’t put too many classes into the same package:7+-2 (or even 5+-2)
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 47
Avoid Ravioli Models: Put Taxonomies in a separate View
SavingsAccount
Withdraw()
CheckingAccount
Withdraw()
MortgageAccount
Withdraw()
Account
Amount
Deposit()Withdraw()GetBalance()
CustomerIdAccountIdAccountId
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 48
Object Modeling in Practice: Heuristics
♦ Explicitly schedule a team meeting for object identification
♦ Try to differentiate between entity, boundary and control objects
♦ Find associations and their multiplicityw Unusual multiplicities usually lead to new objects or categories
♦ Identify Aggregation
♦ Identify Inheritance: Look for a Taxonomy, Categorize
♦ Allow time for brainstorming , Iterate, iterate
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 49
Software Engineers are not the only System Analysts
OntologyObject and System boundary identification
PhenomenologyObjects are user defined
Idealism
Naive IdealismObjects exist only in my
imagination. If I close my eyes, they don't exist (Berkeley)
Critical IdealismReality is determined by
our ideas(Kant, Hegel, Schopenhauer)
Materialism
MarxIdeas are determined
by the economic reality
DialectismIdeas are determined by the dialog between the user and
reality(Sokrates, Hegel, Marx)
Kant Ideas are made up by humans"Ding an sich" :Reason for perception but can never be
seen itself
Schopenhauer
Realism
Naive RealismThings are exactly how we experience
them
PlatoReality can never be seen only its shadow.
Religion
David Hume
Goethe
Dualistic Idealism Monistic Idealism
Steiner
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 50
What is a Software Engineer?
♦ From the point of view of phenomenology, SoftwareEngineers are dialectic monistic idealists:w Idealists:
t They accept that ideas (called requirements or “customer’s wishlist”)are different from reality.
t The reality might not yet exist (“Vaporware is always possible ”)
wThey are monistic:t They are optimistic that their ideas can describe reality.
wDialectic:t They do this in a dialogue with the customer
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 51
Summary
In this lecture, we reviewed the construction of the object model fromuse case model. In particular, we described:
♦ Identification of objects
♦ Refinement of objects with attributes and operations
♦ Generalization of concrete classes
♦ Identification of associations
♦ Reduction of multiplicity using qualification.
In the next lecture, we describe the construction of the dynamic modelfrom the use case and object models.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 52
5.6 Consider the object model below (adapted from [Jackson, 1995]):
Given your knowledge of the Gregorian calendar, list all the problemswith this model. Modify it to correct each of them.
Exercises
Year
Month
Week
Day
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 53
Exercises (cont’d)
5.7 Consider the object model of the previous exercise. Usingassociation multiplicity only, can you modify the model such that adeveloper unfamiliar with the Gregorian calendar could deduce thenumber of days in each month? Identify additional classes ifnecessary.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 54
Next Steps
♦ For all students:w Tomorrow: Requirements Elicitation Tutorial (REQ/QOC)w Next Thursday: Configuration Management
w Next Friday: TogetherJ Tutorial
♦ For STARS students:w GUI Mockup due tomorrow on Notes Bboard
t 2-3 slides + name of presenter for each team
w GUI Mockup review on Monday 14:15