Lecture 11: Design Patterns, Modeling Interactions and Behavior Flashcards
What are design patterns?
Recurring aspects of design. A pattern is a general, reusable solution
Good patterns are as general as possible and have an effective solution
What makes up a design pattern?
Context: The general situation in which the pattern applies
Problem: Short description of the main difficulty tackled
Forces: Issues or concerns to consider when solving the problem
Solution: Recommended way to solve the problem
What is an abstraction-occurrence pattern?
Context: Domain models often contain sets of related objects (occurrences)
Problem: Finding the best way to represent such occurrences in a class diagram
Forces: Want to avoid duplicating common information
Solution: Create an Abstraction class that contains data common to all members, then create an Occurrence class representing the occurrences of this abstraction. Connect the classes with a one-to-many association
What is a general hierarchy pattern?
Context: Objects may form a hierarchy
Problem: Representing a hierarchy with limits
Forces: Objects have many common properties
Solution: Create a Node class containing all the features possessed by all objects in the hierarchy. Create a SuperiorNode and link it via Subordinates to the superclass. Create NonSuperiorNode, cannot be linked with subordinates
What are aggregations?
Special associations representing “part-whole” relationships. “Whole” side is an aggregate. Denoted by a diamond
Ex: Vehicle <> —– VehiclePart
What is a player-role pattern?
Context: An object has a particular set of properties (a role)
Problem: Ability to change role
Force: Improve encapsulation, avoid multiple inheritance
Solution: Create a Player class for the object, create an association to an AbstractRole class (which has varying sub classes)
What is the singleton pattern?
Context: Classes for which only one instance should exist
Problem: Ensure it is impossible to make more
Forces: Public constructor can’t guarantee this
Solution: Private class variable that stores the instance. Public method, getInstance(), instantiates on first invocation. Subsequent calls return theInstance
What is the delegation pattern?
Context: Two classes, one provides service and the other desires it
Problem: Make use of method in another class
Forces: Inheritance isn’t appropriate
Solution: Create a Delegator class with a method that calls another method in Delegate
What is the immutable pattern?
Context: Object that contains a state which never changes after creation
Problem: Creating immutable instances of a class
Forces: No loopholes permitting modification of object
Solution: Ensure values for the instance variables are only set/modified in the constructor
How is a sequence diagram set up?
Shows the sequence of messages exchanged by a set of objects performing a specific task
Actor (stick figure) on left
Messages are arrows between sender and receiver
Class instances are boxes with class and object identifiers underlined
Vertical dimension represents time
How is an activity diagram set up?
Similar to state diagram except transitions caused by internal events (e.g. completion of computation)
Help understand object or component work flow
Can represent concurrency
How is a state diagram set up?
Describe the behavior of a system, part of a system, or an individual object
Directed graph, where nodes are states and arcs are transitions
System or object is always in some state
Event causes transitions, labeled
Black circle: Start state
Circle with a ring around it: End state
What is a fork?
In an activity diagram, there is one incoming transition and multiple outgoing transitions
What is a join?
In an activity diagram, there are multiple incoming transitions and one outgoing transition
All incoming transitions must occur before proceeding
What is a rendezvous?
In an activity diagram, there are multiple incoming and multiple outgoing transitions
All incoming transitions must occur first