Module design_pattern_examples_rust::proxy
source · Expand description
The Proxy design pattern example module
The Proxy pattern is used when a large or expensive object cannot be represented directly in the program, typically because the object is in another process or even another system altogether.
In this exercise, a Proxy struct implements the same trait as the Real struct, making the Proxy struct look like the Real struct. Calls made on the Proxy struct are passed to the Real struct where the work is actually done (in this case, a munged string with the text “Real struct received ‘xxxx’”.
Accessed through the proxy_exercise() function.
Modules
- Contains the IWorkByProxy trait that is implemented on both the proxy object and the real object.
- Contains the ProxyEntity struct that locally represents a (possibly remote) real entity. In this example, the real entity being proxied is located in its own module.
- Contains the RealEntity struct that represents a (possibly remote) entity for which a proxy is needed. In this example, the RealEntity is located in its own module.
Functions
- Example of using the “Proxy” design pattern.