Jump to Menu

Proxy Pattern Tutorial

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

Compatible edition(s): Enterprise, Professional, Standard

  • October 7, 2009
  • Views: 42,198
  • PDF

Modeling Design Pattern with Class Diagram

  1. Create a new project Design Patterns.
  2. Create a class diagram Proxy.
    new diagram
  3. Select Class from diagram toolbar. Click on the diagram to create a class. Name it as Client.
    create client class
  4. Move the mouse cursor over the Client class, and drag out Association > Class to create an associated class Subject.
    create subject class
  5. Right-click on Subject, and select Model Element Properties > Abstract to set it as abstract.
    abstract subject
  6. Right-click on the Subject class, and select Add > Operation from the popup menu.
    add subject oper
  7. Name the operation Request().
  8. Right-click on Request, and select Model Element Properties > Abstract to set it as abstract.
    set request abstract
  9. Move the mouse cursor over the Subject class, and drag out Generalization > Class to create a subclass RealSubject.
    create real subject
  10. Repeat the previous step to create another subclass from Subject, namely Proxy.
    created proxy
  11. In practice, there may be multiple requests. To represent this, stereotype the class Subject as PTN Members Creatable. Right-click on Subject and select Stereotypes > Stereotypes... from the popup menu.
    stereotype subject class
  12. In the Stereotypes tab of the Class Specification dialog box, select PTN Members Creatable and click > to assign it to Subject class. Click OK to confirm.
    stereotype ptn members creatable
    Up to now, the diagram should look like this:
    pattern modeled

Defining Pattern

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

Applying Design Pattern on Class Diagram

In this section, we are going to apply the proxy pattern in modeling a client class that talks to a proxy account class.

  1. Create a new project Account Management.
  2. Create a class diagram Domain Model.
  3. Right-click on the class diagram and select Utilities > Apply Design Pattern... from the popup menu.
    apply design pattern
  4. In the Design Pattern dialog box, select Proxy from the list of patterns.
    select proxy
  5. Click on Subject in the overview.
    select subject
  6. Rename Subject to Account, and operation Request to Create at the bottom pane.
    rename subject
  7. Besides the operation Create, we also need two more operations for Suspend and Delete. Keep Subject selected, click on the + button at the bottom pane, and select New Operation... from the popup menu.
    select new oper
  8. In the Operation Specification dialog box, name the operation Suspend.
    name suspend oper
  9. Repeat steps 7 and 8 to create operation Delete.
    new opers in subject
  10. Select RealSubject in overview, and rename it as RealAccount at the bottom pane.
    rename real subject
  11. Select Proxy in overview, and rename it as AccountProxy at the bottom pane. Click OK to apply the pattern to diagram.
    rename proxy
  12. We need to make the real object and the proxy class inherit operations from the subject class. Right-click on RealAccount and AccountProxy, and select Related Elements > Realize all Interfaces from the popup menu.
    realize interfaces
    The diagram should look like:
    result



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