UsingUML,Patterns,andJava
Object-OrientedSoftwareEngineering Chapter 2,
Modeling with UML
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
Overview: modeling w...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3
What is modeling?
♦ ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
Example: street map
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Why model software?
...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
Systems, Models and ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
Systems, Models and ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
Models, Views and Sy...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
Application and Solu...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
Object-oriented Mod...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
What is UML?
♦ UML ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
UML: First Pass
♦ Y...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
UML First Pass
♦ Us...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14
UML Core Convention...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
UML first pass: Use...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
Historical Remark: ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
UML first pass: Cla...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
UML first pass: Cla...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
Message
UML first p...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20
UML first pass: Sta...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
Other UML Notations...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22
What should be done...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23
UML Basic Notation ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24
Outline of this Cla...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25
UML Basic Notation:...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26
UML Use Case Diagra...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27
Actors
♦ An actor i...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28
Use Case
• A use ca...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29
Textual Use Case
De...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30
Uses Cases can be r...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31
The <<extends>> Rel...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32
The <<includes>> Re...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 33
Class Diagrams
♦ Cl...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34
Classes
♦ A class r...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35
Instances
♦ An inst...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36
Actor vs Class vs O...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37
Associations
Associ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38
1-to-1 and 1-to-man...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39
Many-to-Many Associ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40
From Problem Statem...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41
From Problem Statem...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42
Aggregation
♦ An ag...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43
Qualifiers
♦ Qualif...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44
Qualification: Anot...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45
Inheritance
♦ Inher...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 46
Packages
♦ Packages...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 47
Object Modeling in ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 48
Object Modeling in ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 49
Object Modeling in ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 50
Object Modeling in ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 51
Practice Object Mod...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 52
Practice Object Mod...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 53
Practice Object Mod...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 54
Sequence Diagrams
♦...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 55
Sequence Diagrams c...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 56
Sequence Diagrams: ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 57
Creation and destru...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 58
Sequence Diagram Pr...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 59
Activity Diagrams
♦...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 60
Activity Diagrams a...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 61
Activity Diagrams c...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 62
Activity Diagrams: ...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 63
Activity Diagram vs...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 64
UML Summary
♦ UML p...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 65
Additional Referenc...
Upcoming SlideShare
Loading in …5
×

Ch02lect1 ud

1,357 views

Published on

2 Comments
2 Likes
Statistics
Notes
No Downloads
Views
Total views
1,357
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
73
Comments
2
Likes
2
Embeds 0
No embeds

No notes for slide
  • Statechart diagrams
    Describe the dynamic behavior of an individual object (essentially a finite state automaton)
    Activity Diagrams
    Model the dynamic behavior of a system, in particular the workflow (essentially a flowchart)
  • Represent behavior of single objects with interesting dynamic behavior in terms of states and transitions
    The behavior of the single object Watch, for example, has several different interesting states, BlinkHours, BlinkMinutes, BlinkSeconds,
    Because in each state pressing a button or two yields a different result.
  • In particular, in the lecture on System Design we introduced Deployment Diagrams, in the lecture on Testing we introduce Profiles.
    There is also a language to constrain the systems that can be instantiated from models. The language that has been designed to constain UML models is called OCL (Object constraint language) Introduced in lecture on Object Design
  • Powerful, but complex language
    Warning: Can also be misused to generate unreadable models
    Warning: Can be misunderstood when using too many exotic features
  • We provided already a basic overview of the notations:
    Use case diagrams
    Class diagrams
    Sequence diagrams, statechart diagrams
    We will now go int more detail and cover two additional notations as well, sequence diagrams and activity diagrams
  • Powerful, but complex language
    Can be misused to generate unreadable models
    Can be misunderstood when using too many exotic features
  • Question: Anything missing? Answer: Exceptional cases!
    Use cases represent functionality of the system
    All use cases need to be described for the model to be useful
    Use case diagrams are useful as an index into the use cases
    The Textual Use case descriptions provide meat of model, not the use case diagrams.
  • What is the difference between an actor, a class and an instance?
  • A stock exchange lists many companies each of them uniquely identifed by a ticker symbol used at that stock exchange.
    A company can be listed on more than one stock exchange, using the same ticker symbol.
    Mercedes Benz is an example for a company listed on more than one stock exchange: Frankfurt and NYSE.
    Does it have two different Ticker symbols?
    Something not clear here: What happens if the company cannot have the same ticker symbol on two different stock exchanges?
  • Example for composition: Bill of Material
  • In this case, filename is a qualifier attached to Directory
  • Later we will also see how inheritance allows the reuse of solutions (implementation and specification inheritance)
  • Packages are the grouping construct with
  • Naming is important!
  • There are two types of states:
    Action state:
    Cannot be decomposed any further
    Happens “instantaneously” with respect to the level of abstraction used in the model
    Activity state:
    Can be decomposed further
    The activity is modeled by another activity diagram
  • Statechart Diagram for Incident (similar to Mealy Automaton)
    Activity Diagram for Incident (similar to Moore Automaton)
  • Also:
    - Together Designer 2006 for Eclipse
    - Together Designer 2005, for Microsoftィ Visual Studio.NET 2003
    - Together Designer 2005, for JBuilderィ 2005
  • Ch02lect1 ud

    1. 1. UsingUML,Patterns,andJava Object-OrientedSoftwareEngineering Chapter 2, Modeling with UML
    2. 2. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2 Overview: modeling with UML ♦ What is modeling? ♦ What is UML? ♦ Use case diagrams ♦ Class diagrams ♦ Sequence diagrams ♦ Activity diagrams
    3. 3. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3 What is modeling? ♦ Modeling consists of building an abstraction of reality. ♦ Abstractions are simplifications because:  They ignore irrelevant details and  They only represent the relevant details. ♦ What is relevant or irrelevant depends on the purpose of the model.
    4. 4. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4 Example: street map
    5. 5. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5 Why model software? Why model software? ♦ Software is getting increasingly more complex  Windows XP > 40 million lines of code  A single programmer cannot manage this amount of code in its entirety. ♦ Code is not easily understandable by developers who did not write it ♦ We need simpler representations for complex systems  Modeling is a means for dealing with complexity
    6. 6. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6 Systems, Models and Views ♦ A model is an abstraction describing a subset of a system ♦ A view depicts selected aspects of a model ♦ A notation is a set of graphical or textual rules for depicting views ♦ Views and models of a single system may overlap each other Examples: ♦ System: Aircraft ♦ Models: Flight simulator, scale model ♦ Views: All blueprints, electrical wiring, fuel system
    7. 7. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7 Systems, Models and Views System View 1 Model 2 View 2 View 3 Model 1 Aircraft Flightsimulator Scale Model Blueprints Electrical Wiring
    8. 8. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8 Models, Views and Systems (UML) System Model View ** Depicted byDescribed by Airplane: System Blueprints: View Fuel System: View Electrical Wiring: View Scale Model: Model Flight Simulator: Model
    9. 9. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9 Application and Solution Domain ♦ Application Domain (Requirements Analysis):  The environment in which the system is operating ♦ Solution Domain (System Design, Object Design):  The available technologies to build the system
    10. 10. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10 Object-oriented Modeling Application Domain (Phenomena) Solution Domain (Phenomena) System Model (Concepts) System Model (Concepts) Aircraft TrafficController FlightPlanAirport MapDisplay FlightPlanDatabase Summary Display TrafficControl TrafficControl UML Package (Analysis) (Design)
    11. 11. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11 What is UML? ♦ UML (Unified Modeling Language)  Nonproprietary standard for modeling software systems, OMG  Convergence of notations used in object-oriented methods  OMT (James Rumbaugh and collegues)  Booch (Grady Booch)  OOSE (Ivar Jacobson) ♦ Current Version: UML 2.2  Information at the OMG portal http://www.uml.org/ ♦ Commercial tools: Rational (IBM),Together (Borland), Visual Architect (business processes, BCD) ♦ Open Source tools: ArgoUML, StarUML, Umbrello ♦ Commercial and Opensource: PoseidonUML (Gentleware)
    12. 12. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12 UML: First Pass ♦ You can model 80% of most problems by using about 20% UML ♦ We teach you those 20% ♦ 80-20 rule: Pareto principle  http://www.ephorie.de/hindle_pareto-prinzip.htm
    13. 13. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13 UML First Pass ♦ Use case diagrams  Describe the functional behavior of the system as seen by the user ♦ Class diagrams  Describe the static structure of the system: Objects, attributes, associations ♦ Sequence diagrams  Describe the dynamic behavior between objects of the system ♦ Statechart diagrams  Describe the dynamic behavior of an individual object ♦ Activity diagrams  Describe the dynamic behavior of a system, in particular the workflow.
    14. 14. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14 UML Core Conventions ♦ All UML Diagrams denote graphs of nodes and edges  Nodes are entities and drawn as rectangles or ovals  Rectangles denote classes or instances  Ovals denote functions • Names of Classes are not underlined • SimpleWatch • Firefighter • Names of Instances are underlined • myWatch:SimpleWatch • Joe:Firefighter • An edge between two nodes denotes a relationship between the corresponding entities
    15. 15. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15 UML first pass: Use case diagrams Use case diagrams represent the functionality of the system from user’s point of view Actor. Use Case System boundary Classifier
    16. 16. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16 Historical Remark: UML 1 used packages WatchUser Actor Use casePackage Watch Use case diagrams represent the functionality of the system from user’s point of view ReadTime SetTime ChangeBattery WatchRepairPerson
    17. 17. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17 UML first pass: Class diagrams Class Association Multiplicity Class diagrams represent the structure of the system 2 1 1 1 1 1 1 2 SimpleWatch Display Battery TimePushButton
    18. 18. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18 UML first pass: Class diagrams 1 2 push() release() 1 1 blinkIdx blinkSeconds() blinkMinutes() blinkHours() stopBlinking() referesh() LCDDisplay Battery Load 1 2 1 Time Now 1 Watch Operations state PushButton Attribute Class diagrams represent the structure of the system Class Association Multiplicity
    19. 19. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19 Message UML first pass: Sequence diagram :Time:Watch:WatchUser Object Activation Sequence diagrams represent the behavior of a system as messages (“interactions”) between different objects Actor pressButton1() Lifeline blinkHours() pressButton2() incrementMinutes() :LCDDisplay pressButton1and2() commitNewTime() stopBlinking() refresh() pressButton1() blinkMinutes()
    20. 20. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20 UML first pass: Statechart diagrams State Initial state Final state Transition Event Represent behavior of a single object with interesting dynamic behavior. button1&2Pressed button1Pressed button2Pressed button2Pressed button2Pressed button1Pressed button1&2Pressed Increment Minutes Increment Hours Blink Hours Blink Seconds Blink Minutes Increment Seconds Stop Blinking
    21. 21. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21 Other UML Notations UML provides many other notations, for example ♦ Deployment diagrams for modeling configurations  Useful for testing and for release management ♦ We introduce these and other notations as we go along in the lectures  OCL: A language for constraining UML models
    22. 22. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22 What should be done first? Coding or Modeling? ♦ It all depends…. ♦ Forward Engineering  Creation of code from a model  Start with modeling  Greenfield projects ♦ Reverse Engineering  Creation of a model from existing code  Interface or reengineering projects ♦ Roundtrip Engineering  Move constantly between forward and reverse engineering  Reengineering projects  Useful when requirements, technology and schedule are changing frequently.
    23. 23. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23 UML Basic Notation Summary ♦ UML provides a wide variety of notations for modeling many aspects of software systems ♦ Today we concentrated on a few notations:  Functional model: Use case diagram  Object model: Class diagram  Dynamic model: Sequence diagrams, statechart
    24. 24. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24 Outline of this Class ♦ Use case diagrams  Describe the functional behavior of the system as seen by the user ♦ Class diagrams  Describe the static structure of the system: Objects, attributes, associations ♦ Sequence diagrams  Describe the dynamic behavior between objects of the system ♦ Statechart diagrams  Describe the dynamic behavior of an individual object ♦ Activity diagrams  Describe the dynamic behavior of a system, in particular the workflow.
    25. 25. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25 UML Basic Notation: First Summary ♦ UML provides a wide variety of notations for modeling many aspects of software systems ♦ In the first lecture we concentrated on:  Functional model: Use case diagram  Object model: Class diagram  Dynamic model: Sequence diagrams, statechart ♦ Now we go into a little bit more detail…
    26. 26. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26 UML Use Case Diagrams An Actor represents a role, that is, a type of user of the system Passenger PurchaseTicket Used during requirements elicitation and analysis to represent external behavior (“visible from the outside of the system”) Use case model: The set of all use cases that completely describe the functionality of the system. A use case represents a class of functionality provided by the system
    27. 27. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27 Actors ♦ An actor is a model for an external entity which interacts (communicates) with the system:  User  External system (Another system)  Physical environment (e.g. Weather) ♦ An actor has a unique name and an optional description ♦ Examples:  Passenger: A person in the train  GPS satellite: An external system that provides the system with GPS coordinates. Passenger Name Optional Description
    28. 28. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28 Use Case • A use case represents a class of functionality provided by the system • Use cases can be described textually, with a focus on the event flow between actor and system • The textual use case description consists of 6 parts: 1. Unique name 2. Participating actors 3. Entry conditions 4. Exit conditions 5. Flow of events 6. Special requirements. PurchaseTicket
    29. 29. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29 Textual Use Case Description Example 1. Name: Purchase ticket 2. Participating actor: Passenger 3. Entry condition: ♦ Passenger stands in front of ticket distributor ♦ Passenger has sufficient money to purchase ticket 4. Exit condition: ♦ Passenger has ticket 5. Flow of events: 1. Passenger selects the number of zones to be traveled 2. Ticket Distributor displays the amount due 3. Passenger inserts money, at least the amount due 4. Ticket Distributor returns change 5. Ticket Distributor issues ticket 6. Special requirements: None. Passenger PurchaseTicket
    30. 30. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30 Uses Cases can be related ♦ Extends Relationship  To represent seldom invoked use cases or exceptional functionality ♦ Includes Relationship  To represent functional behavior common to more than one use case.
    31. 31. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31 The <<extends>> Relationship ♦ <<extends>> relationships model exceptional or seldom invoked cases ♦ The exceptional event flows are factored out of the main event flow for clarity ♦ The direction of an <<extends>> relationship is to the extended use case ♦ Use cases representing exceptional flows can extend more than one use case. Passenger PurchaseTicket TimeOut <<extends>> NoChange <<extends>>OutOfOrder <<extends>> Cancel <<extends>>
    32. 32. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32 The <<includes>> Relationship ♦ <<includes>> relationship represents common functionality needed in more than one use case ♦ <<includes>> behavior is factored out for reuse, not because it is an exception ♦ The direction of a <<includes>> relationship is to the using use case (unlike the direction of the <<extends>> relationship). Passenger PurchaseSingleTicket PurchaseMultiCard <<includes>> CollectMoney <<includes>> NoChange <<extends>> Cancel <<extends>> Cancel <<extends>>
    33. 33. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 33 Class Diagrams ♦ Class diagrams represent the structure of the system ♦ Used  during requirements analysis to model application domain concepts  during system design to model subsystems  during object design to specify the detailed behavior and attributes of classes. Table zone2price Enumeration getZones() Price getPrice(Zone) TarifSchedule * * Trip zone:Zone Price: Price
    34. 34. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34 Classes ♦ A class represents a concept ♦ A class encapsulates state (attributes) and behavior (operations) Table zone2price Enumeration getZones() Price getPrice(Zone) TarifSchedule zone2price getZones() getPrice() TarifSchedule Name Attributes Operations Signature TarifSchedule The class name is the only mandatory information Each attribute has a type Each operation has a signature Type
    35. 35. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35 Instances ♦ An instance represents a phenomenon ♦ The attributes are represented with their values ♦ The name of an instance is underlined ♦ The name can contain only the class name of the instance (anonymous instance) zone2price = { {‘1’, 0.20}, {‘2’, 0.40}, {‘3’, 0.60}} tarif2006:TarifSchedule zone2price = { {‘1’, 0.20}, {‘2’, 0.40}, {‘3’, 0.60}} :TarifSchedule
    36. 36. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36 Actor vs Class vs Object ♦ Actor  An entity outside the system to be modeled, interacting with the system (“Passenger”) ♦ Class  An abstraction modeling an entity in the application or solution domain  The class is part of the system model (“User”, “Ticket distributor”, “Server”) ♦ Object  A specific instance of a class (“Joe, the passenger who is purchasing a ticket from the ticket distributor”).
    37. 37. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37 Associations Associations denote relationships between classes Price Zone Enumeration getZones() Price getPrice(Zone) TarifSchedule TripLeg * * The multiplicity of an association end denotes how many objects the instance of a class can legitimately reference.
    38. 38. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38 1-to-1 and 1-to-many Associations 1-to-1 association 1-to-many association Polygon draw() Point x: Integer y: Integer * Country name:String City name:String 11
    39. 39. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39 Many-to-Many Associations StockExchange Company tickerSymbol**
    40. 40. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40 From Problem Statement To Object Model Class Diagram: StockExchange Company tickerSymbol Lists ** Problem Statement: A stock exchange lists many companies. Each company is uniquely identified by a ticker symbol
    41. 41. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41 From Problem Statement to Code Problem Statement : A stock exchange lists many companies. Each company is identified by a ticker symbol Class Diagram: private Vector m_Company = new Vector(); public int m_tickerSymbol; private Vector m_StockExchange = new Vector(); public class StockExchange { }; public class Company { }; Java Code StockExchange Company tickerSymbolLists ** Associations are mapped to Attributes!
    42. 42. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42 Aggregation ♦ An aggregation is a special case of association denoting a “consists-of” hierarchy ♦ The aggregate is the parent class, the components are the children classes Exhaust system Muffler diameter Tailpipe diameter 1 0..2 TicketMachine ZoneButton 3 A solid diamond denotes composition: A strong form of aggregation where the life time of the component instances is controlled by the aggregate. That is, the parts don’t exist on their won (“the whole controls/destroys the parts”)
    43. 43. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43 Qualifiers ♦ Qualifiers can be used to reduce the multiplicity of an association Directory File filename Without qualification 1 * With qualification 0..1 Directory File 1 filename
    44. 44. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44 Qualification: Another Example *StockExchange CompanyLists *tickerSymbol 1 StockExchange Company tickerSymbol Lists **
    45. 45. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45 Inheritance ♦ Inheritance is another special case of an association denoting a “kind-of” hierarchy ♦ Inheritance simplifies the analysis model by introducing a taxonomy ♦ The children classes inherit the attributes and operations of the parent class. Button ZoneButtonCancelButton
    46. 46. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 46 Packages ♦ Packages help you to organize UML models to increase their readability ♦ We can use the UML package mechanism to organize classes into subsystems ♦ Any complex system can be decomposed into subsystems, where each subsystem is modeled as a package. Account CustomerBank
    47. 47. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 47 Object Modeling in Practice Class Identification: Name of Class, Attributes and Methods Is Foo the right name? Foo Amount CustomerId Deposit() Withdraw() GetBalance()
    48. 48. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 48 Object Modeling in Practice: Brainstorming Foo Amount CustomerId Deposit() Withdraw() GetBalance() Account Amount CustomerId Deposit() Withdraw() GetBalance()Is Foo the right name? “Dada” Amount CustomerId Deposit() Withdraw() GetBalance()
    49. 49. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 49 Object Modeling in Practice: More classes Account Amount Deposit() Withdraw() GetBalance() Customer Name CustomerId CustomerIdAccountIdBank Name 1) Find New Classes 2) Review Names, Attributes and Methods
    50. 50. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 50 Object Modeling in Practice: Associations Account Amount Deposit() Withdraw() GetBalance() Customer Name CustomerId CustomerIdAccountId AccountIdBank Name 1) Find New Classes 2) Review Names, Attributes and Methods 3) Find Associations between Classes owns 4) Label the generic assocations 6) Review associations * 2 *? has 5) Determine the multiplicity of the assocations
    51. 51. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 51 Practice Object Modeling: Find Taxonomies Savings Account Withdraw() Checking Account Withdraw() Mortgage Account Withdraw() Account Amount Deposit() Withdraw() GetBalance() CustomerIdAccountId AccountId Customer Name CustomerId() Has* Bank Name *
    52. 52. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 52 Practice Object Modeling: Simplify, Organize Savings Account Withdraw() Checking Account Withdraw() Mortgage Account Withdraw() Account Amount Deposit() Withdraw() GetBalance() CustomerIdAccountId AccountId Show Taxonomies separately
    53. 53. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 53 Practice Object Modeling: Simplify, Organize Customer Name CustomerId() Account Amount Deposit() Withdraw() GetBalance() CustomerIdAccountId AccountId Bank Name Has** Use the 7+-2 heuristics or better 5+-2!
    54. 54. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 54 Sequence Diagrams ♦ Used during analysis  To refine use case descriptions  to find additional objects (“participating objects”) ♦ Used during system design  to refine subsystem interfaces ♦ Instances are represented by rectangles. Actors by sticky figures ♦ Lifelines are represented by dashed lines ♦ Messages are represented by arrows ♦ Activations are represented by narrow rectangles. selectZone() pickupChange() pickUpTicket() insertCoins() TicketMachine Passenger Focus on control flow Messages -> Operations on participating Object zone2price selectZone() insertCoins() pickupChange() pickUpTicket() TicketMachine
    55. 55. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 55 Sequence Diagrams can also model the Flow of Data ♦ The source of an arrow indicates the activation which sent the message ♦ Horizontal dashed arrows indicate data flow, for example return results from a message Passenger selectZone() ZoneButton TarifSchedule Display lookupPrice(selection) displayPrice(price) price Dataflow …continued on next slide...
    56. 56. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 56 Sequence Diagrams: Iteration & Condition ♦ Iteration is denoted by a * preceding the message name ♦ Condition is denoted by boolean expression in [ ] before the message name Passenger ChangeProcessor insertChange(coin) CoinIdentifier Display CoinDrop displayPrice(owedAmount) lookupCoin(coin) price [owedAmount<0] returnChange(-owedAmount) Iteration Condition …continued on next slide... …continued from previous slide... *
    57. 57. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 57 Creation and destruction ♦ Creation is denoted by a message arrow pointing to the object ♦ Destruction is denoted by an X mark at the end of the destruction activation  In garbage collection environments, destruction can be used to denote the end of the useful life of an object. Passenger ChangeProcessor …continued from previous slide... Ticket createTicket(selection) free() Creation of Ticket Destruction of Ticket print()
    58. 58. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 58 Sequence Diagram Properties ♦ UML sequence diagram represent behavior in terms of interactions ♦ Useful to identify or find missing objects ♦ Time consuming to build, but worth the investment ♦ Complement the class diagrams (which represent structure).
    59. 59. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 59 Activity Diagrams ♦ An activity diagram is a special case of a state chart diagram ♦ The states are activities (“functions”) ♦ An activity diagram is useful to depict the workflow in a system Handle Incident Document Incident Archive Incident
    60. 60. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 60 Activity Diagrams allow to model Decisions Open Incident Notify Police Chief Notify Fire Chief Allocate Resources [fire & highPriority] [not fire & highPriority] [lowPriority] Decision
    61. 61. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 61 Activity Diagrams can model Concurrency ♦ Synchronization of multiple activities ♦ Splitting the flow of control into multiple threads Open Incident Allocate Resources Coordinate Resources Document Incident Archive Incident SynchronizationSplitting
    62. 62. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 62 Activity Diagrams: Grouping of Activities ♦ Activities may be grouped into swimlanes to denote the object or subsystem that implements the activities. Open Incident Allocate Resources Coordinate Resources Document Incident Archive Incident Dispatcher FieldOfficer
    63. 63. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 63 Activity Diagram vs. Statechart Diagram Handle Incident Document Incident Archive Incident Active Inactive Closed Archived Incident- Handled Incident- Documented Incident- Archived Statechart Diagram for Incident Focus on the set of attributes of a single abstraction (object, system) Activity Diagram for Incident (Focus on dataflow in a system) Triggerless transitionCompletion of activity causes state transition Event causes state transition
    64. 64. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 64 UML Summary ♦ UML provides a wide variety of notations for representing many aspects of software development  Powerful, but complex ♦ UML is a programming language  Can be misused to generate unreadable models  Can be misunderstood when using too many exotic features ♦ We concentrated on a few notations:  Functional model: Use case diagram  Object model: class diagram  Dynamic model: sequence diagrams, statechart and activity diagrams
    65. 65. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 65 Additional References ♦ Martin Fowler  UML Distilled: A Brief Guide to the Standard Object Modeling Language, 3rd ed., Addison-Wesley, 2003 ♦ Grady Booch,James Rumbaugh,Ivar Jacobson  The Unified Modeling Language User Guide, Addison Wesley, 2nd edition, 2005 ♦ Commercial UML tools  Rational Rose XDE for Java  http://www-306.ibm.com/software/awdtools/developer/java/  Together (Eclipse, MS Visual Studio, JBuilder)  http://www.borland.com/us/products/together/index.html ♦ Open Source UML tools  http://java-source.net/open-source/uml-modeling  ArgoUML,UMLet,Violet, …

    ×