Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Vfp vs Vb
Message
 
To
06/11/1999 04:02:27
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00283708
Message ID:
00288044
Views:
34
Walter,

Example 2 is a implementation of a strategy pattern. In a stratgey pattern the object that has the specific behavior is not directly exposed to the outside, rather the object that creates the strategy object has an external interface. There is almost always a factory pattern involved. That is, the object with the interface creates the behavior object when it is needed the first time. Then it keeps it in anticipation of the behavior being requested again.

This can be taken to another level by using a bridge. For the bridge example let's assume we need output services in an application. We have three forms, Customer, Invoice, and Payment and they all have to be able to provide output on an printer, fax machine, and through Email. We are interested in solving this problem with a design that is extensible so that any new forms or new output modalities will be absorbed as easilyas possible.

Below is one design;
     |-------------------------------------------------|
     |            Output controller                    |
     |  |-----------|               |----------|       |
     |  | external  |               | behavior |       |
     |  | interface |               |          |       |
     |  |           |               |          |       |
     |  |-----------|               |----------|       |
     |                                                 |
     |                                                 |
     |-------------------------------------------------|
In this example the Output Controller (OC) exposes a single method and that method returns an object reference to an Exterenal Interface (EI) object. The Customer form calls the OC and requests an output service. The OE either creates or finds an EI that meets the demands of the Customer form and returns an object refernce to the form. The form continues to talk to the EI.

When the form informs the EI that it wants to output to Email, the EI calls the OC and requests an Email behavior object, the EI returns the object reference to a Behavior object (B). From then on the EI talks to the B.

Why is htis an effective design? Because when there is an Employee form or any other form the only thing we need to do is create an EI class for that form (only if one of the existing ones can't do the job). Also when Microsoft release the new holographic printer we can incorporate it into our design fairly easily.

This diagram does not look like and inheritance tree because it isn't an inheritance tree. The OC, EI, and B in the diagram will also have inheritance trees that are independent of their use in this design pattern. They could all be subclasses of the same superclass, or they could have very different heirarchies.
Previous
Reply
Map
View

Click here to load this message in the networking platform