500 likes | 526 Views
Learn about the representation and benefits of class diagrams, object diagrams, and associations in UML behavioral modeling. Explore examples and notations to grasp practical concepts effectively. Dive into software design, construction, and testing knowledge areas.
E N D
https://flic.kr/p/7xu9QE Behavioral Modeling with UML
SWEBOK Knowledge Areas • Software Requirements • Software Design • Software Construction • Software Testing • Software Maintenance • Software Configuration Management • Software Engineering Management • Software Engineering Process • Software Engineering Models and Methods • Software Quality • Software Engineering Professional Practice • Software Engineering Economics • Computing Foundations • Mathematical Foundations • Engineering Foundations Today’s topic
Overview • Structural modeling • Behavioral modeling • Brief intro to design patterns
What does a class diagram represent? User name : string email : string buyer 1 seller 1 Has Has Sale purchase sale * * price : integer description : string
What does a class diagram represent? User name : string email : string • Set of possible objects • Instances of each class • Set of possible configurations • Attribute values • Links between objects buyer 1 seller 1 Has Has Sale purchase sale * * price : integer description : string
Pros/cons of class diagram User name : string email : string • Pro: Abstract/General • Represents all possible objects/configurations • Con: Complex • A lot of possibilities to consider buyer 1 seller 1 Has Has Sometimes easier to reason about objects (more concrete) than about classes (more abstract) Sale purchase sale * * price : integer description : string
Object Diagrams Class Diagram Object Diagram ipad sale : Sale surface sale : Sale galaxy sale : Sale Sale price : integer description : string price = 600 description = "Apple iPad" price = 500 description = "Microsoft Surface" price = 250 description = "Samsung Galaxy"
Object Diagram Notation Colon separator Object name Object type Attribute value Underline denotes object (as opposed to class) galaxy sale : Sale Sale Object price : integer description : string price = 250 description = "Samsung Galaxy" Corresponding class:
Object Diagrams Class Diagram Object Diagram Object diagram is snapshot of system at point in time ipad sale : Sale surface sale : Sale galaxy sale : Sale Sale price : integer description : string price = 600 description = "Apple iPad" price = 500 description = "Microsoft Surface" price = 250 description = "Samsung Galaxy"
What about associations? User Class Diagram Object Diagram name : string email : string Has Has buyer 1 seller 1 ipad sale : Sale Sale price = 600 description = "Apple iPad" price : integer description : string purchase sale * *
First, let’s add users User Class Diagram Object Diagram name : string email : string Has Has buyer 1 seller 1 bob : User ipad sale : Sale alice : User Sale price : integer description : string name = "Bob" email = "bob@memphis.edu" name = "Alice" email = "alice@memphis.edu" price = 600 description = "Apple iPad" purchase sale * *
Now, make Alice a seller User Class Diagram Object Diagram name : string email : string Has Has seller Has buyer 1 seller 1 Add a link sale bob : User alice : User ipad sale : Sale Sale price : integer description : string name = "Bob" email = "bob@memphis.edu" name = "Alice" email = "alice@memphis.edu" price = 600 description = "Apple iPad" purchase sale * *
Now, make Alice a seller User Class Diagram Object Diagram name : string email : string No multiplicities on links Has Has seller buyer 1 seller 1 Has sale bob : User alice : User ipad sale : Sale Sale name = "Bob" email = "bob@memphis.edu" name = "Alice" email = "alice@memphis.edu" price = 600 description = "Apple iPad" price : integer description : string purchase sale * *
Lastly, make Bob the buyer User Class Diagram Object Diagram name : string email : string Has Has seller buyer 1 seller 1 Has Has sale bob : User alice : User ipad sale : Sale Sale purchase price : integer description : string name = "Bob" email = "bob@memphis.edu" name = "Alice" email = "alice@memphis.edu" price = 600 description = "Apple iPad" purchase sale * * buyer
Is this valid? User name : string email : string buyer seller purchase buyer 1 seller 1 Has Has Has Has Has Has sale sale surface sale : Sale alice : User bob : User ipad sale : Sale Sale purchase sale * * price : integer description : string price = 600 description = "Apple iPad" price = 500 description = "Microsoft Surface" name = "Bob" email = "bob@memphis.edu" name = "Alice" email = "alice@memphis.edu" purchase buyer seller
Is this valid? Yes! User name : string email : string buyer seller purchase buyer 1 seller 1 Has Has Has Has Has Has sale sale surface sale : Sale alice : User ipad sale : Sale bob : User Sale purchase sale * * price : integer description : string price = 500 description = "Microsoft Surface" name = "Bob" email = "bob@memphis.edu" name = "Alice" email = "alice@memphis.edu" price = 600 description = "Apple iPad" purchase buyer seller
How ’bout this? User name : string email : string buyer purchase sale buyer 1 seller 1 Has Has Has Has Has sale seller chuck : User ipad sale : Sale bob : User alice : User Sale purchase sale * * price : integer description : string name = "Bob" email = "bob@memphis.edu" name = "Alice" email = "alice@memphis.edu" name = "Chuck" email = "chuck@memphis.edu" price = 600 description = "Apple iPad" seller
How ’bout this? No! 1 seller per sale! User name : string email : string buyer purchase sale buyer 1 seller 1 Has Has Has Has Has sale seller bob : User alice : User ipad sale : Sale chuck : User Sale purchase sale * * price : integer description : string name = "Bob" email = "bob@memphis.edu" name = "Alice" email = "alice@memphis.edu" name = "Chuck" email = "chuck@memphis.edu" price = 600 description = "Apple iPad" seller
Note: No inheritance in object diagrams User Spy zed : User wolverine : Spy name : string email : string alias : string name = "Zed" email = "zed@memphis.edu" name = "Logan" email = "logan@mutant.edu" alias = "Wolverine"
Class and object diagrams model structure • What the objects are • How they’re connected • What attributes/operations they have But structure isn’t everything What else might you want to model?
Behavioral Modeling • How objects interact • What messages are exchanged over links • Messages = method calls/returns • Message protocols • Scenarios of interaction • Two notations: • Communication diagram • Sequence diagram
Communication Diagram From The Unified Modeling Language Reference Manual, Second Edition by Rumbaugh et al.
Communication Diagram From The Unified Modeling Language Reference Manual, Second Edition by Rumbaugh et al.
Communication Diagram Binds to object Binds to link
Sequence Diagram From The Unified Modeling Language Reference Manual, Second Edition by Rumbaugh et al.
Sequence Diagram From The Unified Modeling Language Reference Manual, Second Edition by Rumbaugh et al.
Communication and sequence diagrams both represent scenario Why prefer one over other?
Communication and sequence diagrams both represent scenario Why prefer one over other? Communication includes structure Sequence easier to read message exchange
So what are all these notations good for? • Reasoning about your own designs • Understanding other people’s designs • And design patterns!
Required reading for software designers • “Gang of Four” (GoF) book • 23 patterns • Template solutions to common problems
Common Problem: Many objectsinterconnected in complex ways From Design Patterns: Elements of Reusable Object-Oriented Software (Gamma et al., 1995)
Common Problem: Many objectsinterconnected in complex ways ?
Mediator Pattern From Design Patterns: Elements of Reusable Object-Oriented Software (Gamma et al., 1995)
Mediator Pattern From Design Patterns: Elements of Reusable Object-Oriented Software (Gamma et al., 1995)
Application of Mediator Pattern From Design Patterns: Elements of Reusable Object-Oriented Software (Gamma et al., 1995)
Application of Mediator Pattern From Design Patterns: Elements of Reusable Object-Oriented Software (Gamma et al., 1995)
Application of Mediator Pattern From Design Patterns: Elements of Reusable Object-Oriented Software (Gamma et al., 1995)
Summary • Structural modeling with • Class diagrams • Object diagrams • Behavioral modeling with • Communication diagrams • Sequence diagrams