SDSU CS 696: Advanced OO
Spring Semester, 1997
Doc 20, Facade and Proxy

To Lecture Notes Index
San Diego State University -- This page last updated May 1, 1997

Contents of Doc 20, Facade and Proxy

Facade slide # 1
...Review of Wirfs-Brock (CRC Design Process) slide # 1
......Exploratory Phase slide # 2
......Analysis Phase slide # 3
......Subsystems slide # 4
...The Facade Pattern - Basic Idea slide # 5
...Consequences of Facade Pattern slide # 5
Proxy slide # 6
...Reasons for Object Proxies slide # 6


Designing Object-Oriented Software,Wirfs-Brock

Design Patterns: Elements of Resuable Object-Oriented Software, Gamma, Helm, Johnson, Vlissides, Addison-Wesley, 1995

Doc 20, Facade and Proxy Slide # 1


Review of Wirfs-Brock (CRC Design Process)

Who is on the team?

What are their tasks, responsibilities?

Who works with whom?

Who's related to whom?

Finding sub teams

Putting it all together

Doc 20, Facade and Proxy Slide # 2

Exploratory Phase

What are the goals of the system?

What must the system accomplish?

What objects are required to model the system and accomplish the goals?

What does each object have to know in order to accomplish each goal it is involved with?

What steps toward accomplishing each goal is it responsible for?

With whom will each object collaborate in order to accomplish each of its responsibilities?

What is the nature of the objects' collaboration

Doc 20, Facade and Proxy Slide # 3

Analysis Phase

Determine which classes are related via inheritance

Finding abstract classes

Determine class contracts

Divide responsibilities into subsystems

Designing interfaces of subsystems and classes

Construct protocols for each class

Produce a design specification for each class and subsystem

Write a design specification for each contract

Doc 20, Facade and Proxy Slide # 4


Subsystems are groups of classes, or groups of classes and other subsystems, that collaborate among themselves to support a set of contracts

There is no conceptual difference between the responsibilities of a class and a subsystem of classes

The difference between a class and subsystem of classes is a matter of scale

A subsystem should be a good abstraction

There should be as little communication between different subsystems as possible

Doc 20, Facade and Proxy Slide # 5

The Facade Pattern - Basic Idea

Create a class that is the interface to the subsystem

Clients interface with the Facade class to deal with the subsystem

Consequences of Facade Pattern

It hides the implementation of the subsystem from clients

Differences from Mediator

Facade does not add any functionality, Mediator does

Subsystem components are not aware of Facade

Mediator's colleagues are aware of Mediator and interact with it

Doc 20, Facade and Proxy Slide # 6


proxy n. pl prox-ies The agency for a person who acts as a substitute for another person, authority to act for another

Reasons for Object Proxies

Remote Proxy
The actual object is on a remote machine (remote address space)

Hide real details of accessing the object

Used in CORBA

Virtual Proxy

Creates/accesses expensive objects on demand

You may wish to delay creating an expensive object until it is really accessed

It may be too expensive to keep entire state of the object in memory at one time
Protection Proxy
Provides different objects different level of access to original object

Doc 20, Facade and Proxy Slide # 7
Smart Reference

Delete original object when there are no references to it

Lock original object so no other object can modify original

Load persistent object into memory when first referenced

The Pattern

The proxy has the same interface as the original object

Use common interface (or abstract class) for both the proxy and original object

Proxy contains a reference to original object, so proxy can forward requests to the original object

Doc 20, Facade and Proxy Slide # 8
Proxy verses Other Patterns


Decorators add responsibility(ies) to an object

Proxies controls access an object

Chain of Responsibility

Chain can contain many objects

In the chain different objects can perform various requests

Proxy forwards (or not) requests to the original object

A facade represents a system of objects

A proxy represents a single object

A facade simplifies the interact between client and the system

A proxy controls the access to the single object

Doc 20, Facade and Proxy Slide # 9

All the design patterns in the text are based on:

These two elements are used to construct communicating objects and classes that solve a general design problem in a particular context

The structures of different patterns may be similar but the problem each pattern solves is different

Different pattern's problems may overlay at times

The goal is not to produce a disjoint taxonomy of structures but a list of common problems and a general structure for solving them