MTI TEK
  • Home
  • About
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All Resources
Design Patterns | Proxy
  1. References
  2. Example
    • The Subject
    • The Real Subject
    • The Proxy
    • A simple class to test the Proxy design pattern

  1. References
    • Definition: (source: http://en.wikipedia.org/wiki/Proxy_pattern)

      A proxy, in its most general form, is a class functioning as an interface to something else.
      The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate.

    • Class diagram: (source: http://en.wikipedia.org/wiki/Proxy_pattern)

      Proxy Pattern
  2. Example
    • The Subject:

      public interface Logger {
          void log();
      }

    • The Real Subject:

      public class FileLogger implements Logger {
          public void log() {
              System.out.println("FileLogger-log");
          }
      }

    • The Proxy:

      public class ProxyFileLogger implements Logger {
          private final Logger logger = new FileLogger();
      
          public void log() {
              logger.log();
          }
      }

    • A simple class to test the Proxy design pattern:

      public class ProxyPatternTest {
          public static void main(String[] args) {
              // create the proxy
              Logger logger = new ProxyFileLogger();
      
              // call method
              logger.log();
          }
      }

© 2025 mtitek