UML patterns are used to determine responsibility assignment for objects to interact in a collaboration diagram. Patterns are:
* Identified as a solution.
* A solution to a specific problem type. The solution has a name.
* Solution ideas from experts.
There are several different sets of patterns. The patterns used for collaboration diagram responsibility assognment are General Responsibility Assignment Software Patterns (GRASP). There are:
* Low coupling
* High cohesion
* Pure fabrication
* Don't talk to strangers
* Evaluative - Patterns that indicate the degree of flexability of the design.
o Low coupling - Coupling measures how much one class relies on another class or is connected to another class. If there are many lines between objects, coupling is high.
o High cohesion - Keep the class as uncomplicated as possible. Don't perform functions not necessary for the respective class.
* Driving Patterns - Patterns used for problem solving.
o Expert - The responsibility is assigned to the information expert. Who has the required information? Who is the expert with the requested information?
o Creator - The one who creates something. Use the creater pattern when one or more of the following are true:
+ The creating class aggregates the class to be created.
+ The creating class contains the class to be created
+ The creating class closely uses the class to be created
+ The creating class records the class to be created
o Controller - An interface between two layers such as the user and domain layer. This pattern supports low coupling and high cohesion. It handles event messages. Serves as a wrapper for a lower or domain layer. Events are received and passed through the controller.
o Polymorphism - A class that is a subclass of a superclass performs the operation itself. This way an operation sent to the subclass can be the same operation but it is specific for the needs of that subclass. Same message, different method.
o Pure fabrication - Make a class that performs some of the work in order to keep one class less complicated.
o Indirection - Assign responsibility to an intermediate object.
o Don't talk to strangers - Promote the interface. Talking to strangers causes high coupling since the object must interface with many objects. Messages cannot be sent to any other than the following from the method receiving the message:
+ A parameter of the method called by the message.
+ The self object which is the receiver.
+ A receiver attribute that references another object or an element in the referenced collection object.
+ An object that the method created.
This pattern is being replaced by one called "Protected Variation" which is a synonym to the open/close principles. The open close principles mean the design is open to extension but it is closed to modification. Many times Generalization is used to support this. Additional generalizations (or subclasses) can be added to objects without changing surounding objects.
* Design Patterns
o Singleton (GoF) - Ensure a class has one instance and provide a global path to it. How to implement using java.
o State (GoF) - The state pattern passes a reference to the state it wants to set.
o Class Depot
o public static getInstance() //Get instance of the single depot
o return instance;
o private static Depot instance = new Depot();
o private Depot()
Java creates the depot the first time getInstance() is called.
o Prototype - Used to make a copy of an object so the copy can be modified without changing the original.
o Flyweight - Don't make the object copy until you change it. References the template directly then apply prototype when a change is made. This pattern uses less memory by not actually making the copy until required.
o Facade (GoF) - An object represents the system as a controller.
o Command - A class for each message. The message is a command. The class has an execute method.
o Forwarder-Receiver (Siemens) - For message handling.
o Layers (Siemens) - Place login in the domain layer, not presentation layer.
o Model-View Separation (Domain-Presentation Separation) - Domain objects do not directly send messages to presentation objects. View objects send messages to domain objects to get information to display.
o Publish-Subscribe (Observer) - A means of allowing the presentation layer to get events to display from the domain layer without polling. An object in the presentation layer would subscribe to be notified of events in the domain layer.
Proxy/Remote Proxy (GoF) - Make a class that represents the actual class invloved and let the local class communicate with the actual class.
The power of patterns comes with combining them. Design patterns are for specific coding solutions.