Using UML Patterns and Java ObjectOriented Software Engineering
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 2, Modeling with UML
Use Case Diagrams: Summary ¨ ¨ Use case diagrams represent external behavior Use case diagrams are useful as an index into the use cases Use case descriptions provide meat of model, not the use case diagrams. All use cases need to be described for the model to be useful. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
Class Diagrams ¨ ¨ Class diagrams represent the structure of the system Used w during requirements analysis to model application domain concepts w during system design to model subsystems w during object design to specify the detailed behavior and attributes of classes. Tarif. Schedule Table zone 2 price Enumeration get. Zones() Price get. Price(Zone) Bernd Bruegge & Allen H. Dutoit * * Object-Oriented Software Engineering: Using UML, Patterns, and Java Trip zone: Zone Price: Price 3
Classes Type Name Tarif. Schedule zone 2 price get. Zones() get. Price() ¨ ¨ Tarif. Schedule Table zone 2 price Enumeration get. Zones() Price get. Price(Zone) Attributes Operations Signature Tarif. Schedule A class represents a concept A class encapsulates state (attributes) and behavior (operations) Each attribute has a type Each operation has a signature The class name is the only mandatory information Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
Instances tarif 2006: Tarif. Schedule zone 2 price = { {‘ 1’, 0. 20}, {‘ 2’, 0. 40}, {‘ 3’, 0. 60}} ¨ ¨ : Tarif. Schedule zone 2 price = { {‘ 1’, 0. 20}, {‘ 2’, 0. 40}, {‘ 3’, 0. 60}} 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) Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Actor vs Class vs Object ¨ Actor w An entity outside the system to be modeled, interacting with the system (“Passenger”) ¨ Class w An abstraction modeling an entity in the application or solution domain w The class is part of the system model (“User”, “Ticket distributor”, “Server”) ¨ Object w A specific instance of a class (“Joe, the passenger who is purchasing a ticket from the ticket distributor”). Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
Associations Tarif. Schedule Trip. Leg Enumeration get. Zones() Price get. Price(Zone) * * Price Zone Associations denote relationships between classes The multiplicity of an association end denotes how many objects the instance of a class can legitimately reference. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
1 -to-1 and 1 -to-many Associations Country 1 name: String 1 City name: String 1 -to-1 association Polygon * Point x: Integer y: Integer draw() 1 -to-many association Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
Many-to-Many Associations Company Stock. Exchange Bernd Bruegge & Allen H. Dutoit * * ticker. Symbol Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
From Problem Statement To Object Model Problem Statement: A stock exchange lists many companies. Each company is uniquely identified by a ticker symbol Class Diagram: Stock. Exchange * Bernd Bruegge & Allen H. Dutoit * Lists Company ticker. Symbol Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
From Problem Statement to Code Problem Statement : A stock exchange lists many companies. Each company is identified by a ticker symbol Class Diagram: Stock. Exchange * Lists * Company ticker. Symbol Java Code public class Stock. Exchange { private Vector m_Company = new Vector(); }; Associations are mapped to Attributes! public class Company { public int m_ticker. Symbol; private Vector m_Stock. Exchange = new Vector(); }; Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
Aggregation ¨ ¨ An aggregation is a special case of association denoting a “part-of” hierarchy Exhaust system The aggregate is the parent class, the components are the children classes 0. . 2 1 Muffler Tailpipe diameter 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 own (“the whole controls/destroys the parts”) Ticket. Machine 3 Zone. Button Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
Qualifiers Without qualification Directory 1 * File filename With qualification Directory ¨ ¨ filename 1 1 File Qualifiers identify subsets of related instances in association navigations; they provide a model of indices or keys for association ends. Qualifiers can be used to reduce the multiplicity of an association Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
Qualification: Another Example Person Bank Bernd Bruegge & Allen H. Dutoit * * Lists account. Number * account. Number 0. . 1 * Object-Oriented Software Engineering: Using UML, Patterns, and Java Person 14
Inheritance Button Cancel. Button ¨ ¨ ¨ Zone. Button 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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
Packages ¨ ¨ Packages help you to organize UML models to increase their readability We can use the UML package mechanism to organize classes into subsystems Account Bank ¨ Customer Any complex system can be decomposed into subsystems, where each subsystem is modeled as a package. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
Object Modeling in Practice Foo Amount Customer. Id Deposit() Withdraw() Get. Balance() Class Identification: Name of Class, Attributes and Methods Is Foo the right name? Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
Object Modeling in Practice: Brainstorming Foo “Dada” Amount Customer. Id Deposit() Withdraw() Get. Balance() Account Amount Customer. Id Is Foo the right name? Bernd Bruegge & Allen H. Dutoit Deposit() Withdraw() Get. Balance() Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
Object Modeling in Practice: More classes Account Amount Account. Id Customer. Id Bank Deposit() Withdraw() Get. Balance() Name Customer. Id 1) Find New Classes 2) Review Names, Attributes and Methods Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
Object Modeling in Practice: Associations Account * Bank has Name Amount Account. Id Customer. Id Account. I d Deposit() Withdraw() Get. Balance() * Customer owns 2 Name Customer. Id 1) Find New Classes 2) Review Names, Attributes and Methods 3) Find Associations between Classes 4) Label the generic assocations 5) Determine the multiplicity of the assocations 6) Review associations Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20
Practice Object Modeling: Find Taxonomies Account Bank * Name Savings Account Withdraw() Bernd Bruegge & Allen H. Dutoit Amount Account. Id Customer. Id Account. I d Deposit() Withdraw() Get. Balance() Checking Account Withdraw() * Customer Has Name Customer. Id() Mortgage Account Withdraw() Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
Practice Object Modeling: Simplify, Organize Account Amount Account. Id Customer. Id Account. I d Deposit() Withdraw() Get. Balance() Savings Account Withdraw() Bernd Bruegge & Allen H. Dutoit Checking Account Withdraw() Show Taxonomies separately Mortgage Account Withdraw() Object-Oriented Software Engineering: Using UML, Patterns, and Java 22
Practice Object Modeling: Simplify, Organize Bank Name Bernd Bruegge & Allen H. Dutoit Account * Amount Account. Id Customer. Id Account. I d Deposit() Withdraw() Get. Balance() * Customer Has Object-Oriented Software Engineering: Using UML, Patterns, and Java Name Customer. Id() 23
Sequence Diagrams Focus on control flow ¨ Passenger Ticket. Machine w To refine use case descriptions w to find additional objects (“participating objects”) select. Zone() ¨ insert. Coins() pickup. Change() ¨ Bernd Bruegge & Allen H. Dutoit Used during system design w to refine subsystem interfaces Ticket. Machine zone 2 price Messages -> ¨ Instances are represented by rectangles. select. Zone() Actors by sticky figures. Operations on insert. Coins() participating Object ¨ Lifelines are represented by dashed pickup. Change() lines pick. Up. Ticket() ¨ pick. Up. Ticket() Used during analysis Messages are represented by arrows Activations are represented by narrow rectangles. Object-Oriented Software Engineering: Using UML, Patterns, and Java 24
Sequence Diagrams can also model the Flow of Data Zone. Button Passenger select. Zone() Tarif. Schedule Display lookup. Price(selection) price Dataflow display. Price(price) …continued on next slide. . . ¨ ¨ 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 Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25
Sequence Diagrams: Iteration & Condition …continued from previous slide. . . Passenger Change. Processor *insert. Change(coin) Iteration Condition Coin. Identifier Display Coin. Drop lookup. Coin(coin) value display. Price(owed. Amount) [owed. Amount<0] return. Change(-owed. Amount) …continued on next slide. . . ¨ ¨ Iteration is denoted by a * preceding the message name Condition is denoted by boolean expression in [ ] before the message name Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26
Creation and destruction …continued from previous slide. . . Passenger Change. Processor Creation of Ticket create. Ticket(selection) Ticket print() free() ¨ ¨ Destruction of Ticket 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 w In garbage collection environments, destruction can be used to denote the end of the useful life of an object. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27
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). Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28
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 Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29
Activity Diagrams allow to model Decisions Decision Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30
Activity Diagrams can model Concurrency ¨ ¨ Synchronization of multiple activities Splitting the flow of control into multiple threads Splitting Bernd Bruegge & Allen H. Dutoit Synchronization Object-Oriented Software Engineering: Using UML, Patterns, and Java 31
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 Dispatcher Coordinate Resources Archive Incident Field. Officer Document Incident Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32
Activity Diagram vs. Statechart Diagram for Incident Focus on the set of attributes of a single abstraction (object, system) Event causes state transition Active Inactive Incident. Handled Closed Incident. Documented Archived Incident. Archived Activity Diagram for Incident (Focus on dataflow in a system) Completion of activity causes state transition Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java Triggerless transition 33
UML Summary ¨ UML provides a wide variety of notations for representing many aspects of software development w Powerful, but complex ¨ UML is a programming language w Can be misused to generate unreadable models w Can be misunderstood when using too many exotic features ¨ We concentrated on a few notations: w Functional model: Use case diagram w Object model: class diagram w Dynamic model: sequence diagrams, statechart and activity diagrams Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34
Additional References ¨ Martin Fowler w UML Distilled: A Brief Guide to the Standard Object Modeling Language, 3 rd ed. , Addison-Wesley, 2003 ¨ Grady Booch, James Rumbaugh, Ivar Jacobson w The Unified Modeling Language User Guide, Addison Wesley, 2 nd edition, 2005 ¨ Commercial UML tools w Rational Rose XDE for Java t http: //www-306. ibm. com/software/awdtools/developer/java/ w Together (Eclipse, MS Visual Studio, JBuilder) t ¨ http: //www. borland. com/us/products/together/index. html Open Source UML tools w http: //java-source. net/open-source/uml-modeling w Argo. UML, UMLet, Violet, … Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35
- Slides: 35