1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Using Design Patterns in Java Projects

Proxy

Contents

keyboard_tab
Design Patterns
1
Design Patterns
PREVIEW2m 26s
2
Singleton Pattern
PREVIEW3m 13s
9
Decorator
7m 48s
10
Flyweight
9m 20s
11
Proxy
7m 36s
12
Facade
6m 5s
14
Command
11m 44s
15
Iterator
8m 24s
16
Visitor
9m 4s
17
Mediator
11m 38s
18
Memento
9m 48s
19
Observer
10m 40s
20
Strategy
8m 27s
21
State
10m 27s
22
Template
7m 56s
23
MVC
10m 27s
26
DAO
10m 27s
27

The course is part of this learning path

Start course
Overview
Difficulty
Intermediate
Duration
4h 56m
Students
20
Ratings
5/5
starstarstarstarstar
Description

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.

 

Transcript

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.

 

About the Author
Students
413
Courses
35
Learning Paths
2

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.

Covered Topics