proxy | has definition A pattern found in which a lightweight object stands in place of a heavyweight object that has the same interface. It transparently loads the heavyweight object when needed | |
has antipatterns Instead of using proxy objects, beginner designers often scatter complex code around their application to load objects from databases. A strategy that only works for very small systems is to load the whole database into memory when the program starts. | |
has context - There may be a time-delay and a complex mechanism involved in creating instances of heavyweight classes.
| |
has forces - You want all the objects in a domain model to be available for programs to use when they execute a system's various responsibilities
- It is important for many objects to persist from run to run of the same program
- in a large system it would be impractical for all the objects to be loaded into memory whenever a program starts
- It would be ideal to be able to program the application as if all the objects were located in memory
| |
has problem How can you reduce the need to create instances of a heavyweight class? In particular, how can you reduce the need to load large numbers of them from a database or server, when not all of them will be needed? A related problem is this: If you load one object from a database or server, how can you avoid loading all the other objects that are linked to it. | |
has references one of the Gang of Four patterns | |
has related patterns several patterns that obtain their power from delegating responsibilities to other classes, hence it uses the Delegation pattern | |
has solution - Create a simpler version of the «HeavyWeight» class.
- We will call this simpler version a «Proxy».
- The «Proxy» has the same interface as the «HeavyWeight», so programmers can declare variables without caring whether a «Proxy» or its «HeavyWeight» version will be put in the variable.
| |
is a subtopic of 6.12 - The Proxy Pattern | |
is an instance of design pattern | |
design pattern | has name | |
should be illustrated using a simple diagram | |
should be written using a narrative writing style | |
pattern | should be as general as possible | |
should be described in an easy-to-understand form so that people can determine when and how to use it | |
should contain a solution that has been proven to effectively solve the problem in the indicated context | |