This course takes an in-depth look at how to use design patterns in your Java projects. We will then run through some example questions of what you could expect from the Oracle Certified Java EE exam.
Learning Objectives
- Understand what design patterns are
- Learn about the myriad of design patterns that you can use in your projects
Intended Audience
This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE 6.
Prerequisites
Basic knowledge of Java programming.
Hello, dear friends. In this video, we will examine Proxy Design Pattern. Let's begin. The Proxy Design Pattern is a design pattern belonging to the set of structural patterns. Structural patterns are a category of design patterns used to simplify the design of a program on it's structural level. As its name suggests, the proxy pattern means using a proxy for some other entity. In other words, a proxy is used as an intermediary in front of or wrapped around an existing object. Proxy Design Pattern is used to control access to another object which may be secure or expensive to create. According to the GoF definition of proxy design pattern, a proxy object provides a surrogate or placeholder for another object to control access to it. A proxy is basically a substitute for an intended object which we create due to many reasons, for example, security reasons or cost associated with creating fully initialized original object. So, the famous use case of this is with your Internet usage.
The student is not permitted to access any restricted sites while on school grounds in computer labs. When he tries to access that site, another page appears informing him that it is restricted. If the user is authorized, the site will be opened or access to a secure object will be granted. Otherwise, an error message will be displayed. Let's examine the UML of the proxy pattern. Subject is an interface which exposes the functionality available to be used by the clients. RealSubject is a class implementing subject and it is concrete implementation which needs to be hidden behind a proxy. Proxy hides the real object by extending it and clients communicate to the real objects via this proxy object. Usually frameworks create this proxy object when clients request for the real object. Of course, this pattern provides us some advantages, like, the remote proxy can shield the fact that the implementation resides in another address space. Basically, it provides the protection to the original object from the outside world.
The virtual proxy can perform optimizations like by creating objects on demand. Let's ask another question. When should we use this pattern? The proxy pattern is appropriate when a more versatile or sophisticated reference to an object rather than a simple pointer is needed. Now, I think it's time to create a project using the proxy pattern. Let's create a new project and name it "proxy." As we spoke about Internet usage, let's use a school as an example. First, create Internet Interface. We need a method as connect. Let's define real Internet class. Now also, we need a proxy Internet. First, define real Internet with Internet interface. Now, define a string list as banned lists. Let's add some sites to the list. Now, we have to override connect method. We need a condition to determine is site denied or not. Now, we can write client codes. First, define a proxy Internet. Try to connect four sites. Now, if we run project, we will see three connections and one access denied. Let's try. As you see, we have three successful connections and one access denied. Great. We have now finished the Proxy Design Pattern. In the following video, we will look at our final structural design pattern called Facade. See you in the following video.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.