UML Patterns

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
  • Expert
  • Creator
  • Controller
  • Pure fabrication
  • Indirection
  • Don't talk to strangers
  • Polymorphism

Use Patterns:

  • Evaluative - Patterns that indicate the degree of flexability of the design.
    • 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.
    • 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.
    • Expert - The responsibility is assigned to the information expert. Who has the required information? Who is the expert with the requested information?
    • 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
    • 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.
    • 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.
    • Pure fabrication - Make a class that performs some of the work in order to keep one class less complicated.
    • Indirection - Assign responsibility to an intermediate object.
    • 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
    • Singleton (GoF) - Ensure a class has one instance and provide a global path to it. How to implement using java.
    • State (GoF) - The state pattern passes a reference to the state it wants to set.
      Class Depot
      {
         public static getInstance()  //Get instance of the single depot
         {
            return instance;
         }
         private static Depot instance = new Depot();
         private Depot()
         {
         }
      }
      

      Java creates the depot the first time getInstance() is called.

    • Prototype - Used to make a copy of an object so the copy can be modified without changing the original.
    • 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.
    • Facade (GoF) - An object represents the system as a controller.
    • Command - A class for each message. The message is a command. The class has an execute method.
    • Forwarder-Receiver (Siemens) - For message handling.
    • Layers (Siemens) - Place login in the domain layer, not presentation layer.
    • 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.
    • 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.

Unified Modeling Language Guide Contents Page