官术网_书友最值得收藏!

Explaining Proxy

Sometimes, creating a new object can be a big process and several rules can be involved in creating this object. Imagine that we want to create a list of objects, and these objects represent telecommunication equipment, which has a lot of calculus to generate the information of each object. As well as this, these objects will not be accessed at the same time but will be accessed on demand. A good strategy is to create each object when it is accessed, thereby minimizing the cost and time it takes to create all objects and only access some. The Proxy can help us to solve this.

The Proxy pattern is a pattern that surrogates an object instance (original object) to another object instance (Proxy object) that permitting access control to the original object. In the following diagram, you can see the structure of Proxy and how it is designed:

From the preceding diagram, we can see a structure of the Proxy pattern. If Subject is an interface that clients use to access object operations, then RealSubject is the class of the original object and Proxy is the class that works as a Proxy. Then, when the client accesses the object, they will access the Proxy object, and the Proxy object will then access the RealSubject object and return this object to the client.

This pattern is used in frameworks and APIs that implement JPA specification and object relational mapping (ORM).

主站蜘蛛池模板: 明水县| 五大连池市| 屏边| 霞浦县| 平阴县| 扎赉特旗| 高雄市| 宜良县| 贺兰县| 大邑县| 诸暨市| 咸阳市| 宝兴县| 乌审旗| 城市| 建始县| 桃园县| 遂川县| 兴义市| 宣武区| 隆尧县| 秭归县| 渭南市| 西盟| 舒兰市| 蒙城县| 云龙县| 镇安县| 囊谦县| 阿克陶县| 定南县| 常山县| 罗源县| 靖远县| 兴和县| 宕昌县| 定结县| 黑水县| 乌苏市| 长顺县| 合水县|