From 3743b47887c6c433745159867e878a75fd4466f5 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 11 Nov 2024 09:24:37 +0100 Subject: [PATCH] added proxy example --- src/learn/simple_proxy/Main.java | 8 ++++++++ src/learn/simple_proxy/Proxy.java | 11 +++++++++++ src/learn/simple_proxy/RealSubject.java | 8 ++++++++ src/learn/simple_proxy/Subject.java | 5 +++++ 4 files changed, 32 insertions(+) create mode 100644 src/learn/simple_proxy/Main.java create mode 100644 src/learn/simple_proxy/Proxy.java create mode 100644 src/learn/simple_proxy/RealSubject.java create mode 100644 src/learn/simple_proxy/Subject.java diff --git a/src/learn/simple_proxy/Main.java b/src/learn/simple_proxy/Main.java new file mode 100644 index 0000000..584a174 --- /dev/null +++ b/src/learn/simple_proxy/Main.java @@ -0,0 +1,8 @@ +package learn.simple_proxy; + +public class Main { + public static void main(String[] args) { + Subject subject = new Proxy(); + subject.request(); + } +} diff --git a/src/learn/simple_proxy/Proxy.java b/src/learn/simple_proxy/Proxy.java new file mode 100644 index 0000000..760002d --- /dev/null +++ b/src/learn/simple_proxy/Proxy.java @@ -0,0 +1,11 @@ +package learn.simple_proxy; + +public class Proxy implements Subject { + private RealSubject realSubject = new RealSubject(); + + @Override + public void request() { + System.out.println("Proxy does some preliminary job and checks"); + realSubject.request(); + } +} diff --git a/src/learn/simple_proxy/RealSubject.java b/src/learn/simple_proxy/RealSubject.java new file mode 100644 index 0000000..c638e12 --- /dev/null +++ b/src/learn/simple_proxy/RealSubject.java @@ -0,0 +1,8 @@ +package learn.simple_proxy; + +public class RealSubject implements Subject { + @Override + public void request() { + System.out.println("Real subject action"); + } +} diff --git a/src/learn/simple_proxy/Subject.java b/src/learn/simple_proxy/Subject.java new file mode 100644 index 0000000..65c8959 --- /dev/null +++ b/src/learn/simple_proxy/Subject.java @@ -0,0 +1,5 @@ +package learn.simple_proxy; + +public interface Subject { + public void request(); +}