Jump to Menu

Facade Pattern Tutorial

This tutorial is aimed to guide the definition and application of Gang of Four (GoF) facade design pattern. By reading this tutorial, you will know how to develop a model for the facade pattern, and how to apply it in practice.

Compatible edition(s): Enterprise, Professional, Standard

  • October 14, 2009
  • Views: 34,133
  • PDF

Modeling Design Pattern with Class Diagram

  1. Create a new project Design Patterns.
  2. Create a class diagram Facade.
    new diagram
  3. Select Package from diagram toolbar. Press on the diagram and drag it towards bottom right to form a package representing a subsystem.
    draw package
  4. Name the package subsystem.
    create sub system
  5. Select Class from diagram toolbar. Click inside subsystem to create a class. Name it as Facade.
    create facade
  6. Right-click on Facade and select Add > Operation from the popup menu.
    add operation
  7. Name the operation ClientRequest. Note that it must be a public operation that enables classes external to the subsystem to access it.
    pattern modeled

Defining Pattern

  1. Select everything on the class diagram.
    select all classes
  2. Right-click on the Singleton class and select Define Design Pattern... from the popup menu.
    define design pattern
  3. In the Define Design Pattern dialog box, specify the pattern name Facade. Keep the file name as is. Click OK to proceed.
    name pattern

Applying Design Pattern on Class Diagram

In this section, we are going to apply the facade pattern in modeling a code generator.

  1. Create a new project Code Generator.
  2. Create a class diagram Generator.
  3. Right-click on the class diagram and select Utilitiews > Apply Design Pattern... from the popup menu.
    apply design pattern
  4. In the Design Pattern dialog box, select Facade from the list of patterns.
    select facade
  5. Select subsystem in the overview pane.
    select subsystem
  6. At the bottom pane, rename subsystem to generator. Rename Facade to CodeGenerator and ClientRequest to generate.
    rename facade
  7. Click OK to apply the pattern. This is the diagram obtained:
    result
  8. 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.
    create class builder
  9. Right-click on ClassBuilder and select Open Specification from the popup menu.
    open class spec
  10. In the Class Specification, set Visibility to be package. Click OK to confirm.
    select package
  11. Repeat steps 8 to 10 to create classes AttributeBuilder and OperationBuilder.
    subsystem filled



Turn every software project into a successful one.

We use cookies to offer you a better experience. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.

OK