Scala : Proxy Design Pattern

Knoldus Inc.
Aug 31, 2018 · 2 min read

Hi Everyone!
In our previous blogs, we have discussed Decorator design pattern and Adapter design pattern.
Now, its time to discuss another Structural design pattern i.e. the Proxy design pattern. We will implement the same EUGDPR problem using the Proxy design pattern, which we implemented using the Adapter design pattern in our previous blog.

Problem Statement:
Earlier, in many applications, all the user-specific details like username, IP addresses, phone number, etc were logged directly without scrambling it. But after new data protection law i.e. EUGDPR, it is now mandatory to scramble any user-specific data.

Solution:
We will add a proxy class between our logging framework(slf4j) and our client.

What is Proxy design pattern?

A proxy is a class functioning as an interface to something else.

Proxy design pattern focuses on providing a surrogate or placeholder for another object to control access to it.

We will create a LoggerProxy class which will be called before calling Logging framework and it will scramble the logs and call the logging framework methods.

The build.sbt is a file which describes project settings.
We are using the slf4j dependency to add a logging framework to our application.

Client class is the class which will actually call the logging methods.

The LoggerHelper class will scramble the logs.

The LoggerProxy is the new class which will act as a proxy between client and logging framework and will make sure that logs are scrambled before logging.
LoggerProxy will implement the Logger interface which is defined in the slf4j framework.

Hope you liked the blog. Thanks for reading!

Originally published at blog.knoldus.com on August 31, 2018.

Knoldus Inc.

Written by

Group of smart Engineers with a Product mindset who partner with your business to drive competitive advantage | www.knoldus.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade