Implementing the Proxy pattern with Proxy and Reflect
The proxy pattern involves providing an object (the subject, or real object) that fulfills a certain interface. The proxy (a placeholder or wrapper object) controls access to the subject. This allows us to provide additional functionality on top of the subject without changing a consumer’s interactions with the subject.
This means that a proxy needs to provide an interface matching the subject.
By using the proxy pattern, we can intercept all operations on the original object and either pass them through or change their implementation. This follows the open/closed principle, where both the subject and consumer are closed for modification, but the proxy provides us with a hook to extend, which means the design is open to extension.
A redaction proxy implementation
We’ll start with the following implementation class that has a couple of methods that output strings:
class Implementation {
someFn...