feat(hw-03): implement Proxy pattern
This commit is contained in:
@@ -7,6 +7,7 @@ import org.example.adapter.*;
|
|||||||
import org.example.builder.*;
|
import org.example.builder.*;
|
||||||
import org.example.chain.*;
|
import org.example.chain.*;
|
||||||
import org.example.decorator.*;
|
import org.example.decorator.*;
|
||||||
|
import org.example.proxy.*;
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -18,6 +19,7 @@ public class App {
|
|||||||
checkBuilderPattern();
|
checkBuilderPattern();
|
||||||
checkChainPattern();
|
checkChainPattern();
|
||||||
checkDecoratorPattern();
|
checkDecoratorPattern();
|
||||||
|
checkProxyPattern();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkAdapterPattern() {
|
private static void checkAdapterPattern() {
|
||||||
@@ -48,4 +50,11 @@ public class App {
|
|||||||
|
|
||||||
decorator.operation();
|
decorator.operation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void checkProxyPattern() {
|
||||||
|
Service service = new ConcreteService();
|
||||||
|
Service proxy = new ServiceProxy(service);
|
||||||
|
|
||||||
|
proxy.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.example.proxy;
|
||||||
|
|
||||||
|
/** Concrete Service */
|
||||||
|
public class ConcreteService implements Service {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
System.out.println("ConcreteService выполняет операцию");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package org.example.proxy;
|
||||||
|
|
||||||
|
/** Service */
|
||||||
|
public interface Service {
|
||||||
|
void execute();
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.example.proxy;
|
||||||
|
|
||||||
|
/** Service Proxy */
|
||||||
|
public class ServiceProxy implements Service {
|
||||||
|
|
||||||
|
public ServiceProxy(Service service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
System.out.println("ServiceProxy разрешает выполнение операции");
|
||||||
|
service.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Service service;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user