Modeling Design Pattern with Class Diagram
- Create a new project Design Patterns.
- Create a class diagram Facade.
- Select Package from diagram toolbar. Press on the diagram and drag it towards bottom right to form a package representing a subsystem.
- Name the package subsystem.
- Select Class from diagram toolbar. Click inside subsystem to create a class. Name it as Facade.
- Right click on Facade and select Add > Operation from the popup menu.
- Name the operation ClientRequest. Note that it must be a public operation that enables classes external to the subsystem to access it.
- Select everything on the class diagram.
- Right click on the Singleton class and select Define Design Pattern... from the popup menu.
- In the Define Design Pattern dialog box, specify the pattern name Facade. Keep the file name as is. Click OK to proceed.
Applying Design Pattern on Class Diagram
In this section, we are going to apply the facade pattern in modeling a code generator.
- Create a new project Code Generator.
- Create a class diagram Generator.
- Right click on the class diagram and select Utilitiews > Apply Design Pattern... from the popup menu.
- In the Design Pattern dialog box, select Facade from the list of patterns.
- Select subsystem in the overview pane.
- At the bottom pane, rename subsystem to generator. Rename Facade to CodeGenerator and ClientRequest to generate.
- Click OK to apply the pattern. This is the diagram obtained:
- We need to fill in the subsystem. Move the mouse cursor over the CodeGenerator class, and drag out Aggregation > Class to empty region in the package to create a class. Name the class ClassBuilder.
- Right click on ClassBuilder and select Open Specification from the popup menu.
- In the Class Specification, set Visibility to be package. Click OK to confirm.
- Repeat steps 8 to 10 to create classes AttributeBuilder and OperationBuilder.