Introduction to proxy mode of Java design pattern

Understanding and using design patterns can cultivate our good habit of object-oriented programming. At the same time, we can enjoy the fun of ease in practical application.

Proxy is a useful model with many variations. The application occasions cover the small structure to the large structure of the whole system. Proxy means proxy. We may have concepts such as proxy server. The proxy concept can be explained as: there is an intermediate layer between the starting point and the destination, which means proxy.

Definition in design pattern: provide a proxy for other objects to control access to this object.

Why use proxy mode

1. Authorization mechanism users at different levels have different access rights to the same object. For example, in Jive forum system, proxy is used to control the authorization mechanism. There are two kinds of people accessing the Forum: registered users and tourists (unregistered users). Jive uses proxies like forumproxy to control the access rights of these two users to the forum. 2. A client cannot directly operate on an object, but it must interact with that object.

There are two specific cases:

1. If the object is a large picture and takes a long time to display, when the picture is included in the document, open the document with an editor or browser. The document must be opened quickly and cannot wait for the large picture processing to be completed. At this time, a picture proxy needs to be made to replace the real picture. 2. If the object is on a remote server on the Internet, it may be slow to directly operate the object because of the network speed, we can use proxy to replace the object first.

In short, the principle is that objects with high overhead are created only when they are used. This principle can save us a lot of valuable JAVA memory. Therefore, some people think that Java consumes resources and memory. I think this has something to do with programming ideas.

How to use proxy mode

Taking Jive forum system as an example, there are many types of users accessing the forum system: registered ordinary users, forum managers, system managers and tourists. Only registered ordinary users can speak. The forum manager can manage his authorized forum, and the system manager can manage all transactions. These permissions are divided and managed by proxy.

Forum is the core interface of jive. The forum displays the main behaviors related to forum operations, such as forum name, acquisition and modification of forum description, post publishing, deletion and editing, etc.

Users with various levels of permissions are defined in forumpermissions:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>