Scala : Proxy Design Pattern
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.
