Java

Topic: Design pattern

Expain the Proxy and Decorator patterns?

A Proxy is a direct stand-in for another class, and it typically has the same interfaceas that class because it implements a common interface or an abstract class. Theclient object is not aware that it is using a proxy. A Proxy is used when access to theclass the client would like to use must be mediated in a way that is apparent to theclient -- because it requires restricted access or is a remote process, for example.Decorator, like Proxy, is also a stand-in for another class, and it also has the sameinterface as that class, usually because it is a subclass. The intent is different,however. The purpose of the Decorator pattern is to extend the functionality of theoriginal class in a way that is transparent to the client class.Examples of the Decorator pattern in the Java API are found in the classes forprocessing input and output streams. BufferedReader(), for example, makesreading text from a file convenient and efficient:BufferedReader in = new BufferedReader(new FileReader("file.txt"));

Browse random answers: