Skip to main content

Posts

Showing posts with the label Proxy

Make Our Code More Testable with Proxy Design Pattern

If you heard about the term separation of concerns , you could agree this concept is very important for making a system "clean". One of the most important characteristics of a clean system is testable. Let me tell you my story about how I've just come acrosss the design pattern Proxy. Note: to get started, you can find a very simple example of the pattern Proxy  here .  Let's start! I have an interface as below: public interface DocumentGenerator { File generate(Document document) throws BusinessException; } The following is my first implementation for a concrete class of DocumentGenerator . public class DocumentGeneratorImpl implements DocumentGenerator { private Dossier dossier; private Locale locale; public DocumentGeneratorImpl(Dossier dossier, Locale locale) { validateNotNullParams(dossier, locale); this.dossier = dossier; this.locale = locale; } private void validateNotNullParams(LibertyDossier dossier, Locale locale) { if(Objec