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

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).

主站蜘蛛池模板: 公安县| 内黄县| 集安市| 张家口市| 富源县| 广河县| 澄城县| 阿尔山市| 静安区| 翼城县| 梅河口市| 靖安县| 广平县| 八宿县| 肇庆市| 宜川县| 南漳县| 澜沧| 怀宁县| 东城区| 安丘市| 谷城县| 盐源县| 富顺县| 尼勒克县| 林州市| 治县。| 东安县| 洞头县| 桑植县| 荆州市| 华安县| 调兵山市| 沾益县| 昌图县| 兰溪市| 平顶山市| 济宁市| 伽师县| 泗洪县| 柯坪县|