Why proxy pattern?

You probably heard or saw the term "proxy" multiple times in your browser or your OS, and just like me, you did not know what it means or what does it do. In computer science, that is a term to describe a design pattern and I think it is one of the most interesting design pattern. It is such a simple concept, yet effective and it has been used by a lot of developers, especially in the field of networking. This week blog is based on this article.

For starter, according to the Gang of Four, proxy pattern is categorized as Structural design pattern. Its purpose is to act as a simple wrapper for another objects. In other word, the proxy object can be directly accessed by user and it can perform its own logic or configuration changes required by the underlying subject object without having to give the direct access to the subject. By using this pattern, it offers both developers and users the advantages. This pattern is used when commonly used to hide the internal structure and only enable user / client to access a certain part of it, or access control. It can also be used to replace complex or and heavy objects as a skeleton representation. Less popular function of proxy pattern is to prevent data redundancy(ie. load data from disk multiple time) every time the object is called.

The concept of proxy is actually used a lot the real world. Taking the example of a debit card, it is one of the most commonly thing that used this pattern. Every time you swipe or check out with debit card, you are basically telling the system to transfer the money from your bank account to the vendor that you are paying. You can really see that the debit card does not have the trading value, it just represent the amount of money you have in your bank account so that you don't have to carry that amount around.

This applies the same way in computer science. For instance, if you are working on a project where you have to have multiple server to run on separate subdomain, but unfortunately, you only have one server machine, then reverse proxy is definitely a way to go. In Object Oriented Programming, access an object through another object is also really common and useful to ensure security and convenience.


Popular posts from this blog

Designing the code is more important than you thought


Comparing REST and SOAP, which one should you use?