Skip to content

Instantly share code, notes, and snippets.

@vinimonteiro
Created August 2, 2022 05:40
Show Gist options
  • Save vinimonteiro/4357d3fd8d08a164ae99c01a7ffc7b2a to your computer and use it in GitHub Desktop.
Save vinimonteiro/4357d3fd8d08a164ae99c01a7ffc7b2a to your computer and use it in GitHub Desktop.
Proxy dp
public interface Service {
void insert();
}
public class RealService implements Service{
@Override
public void insert() {
System.out.println("Insert");
}
}
public class Proxy implements Service{
private RealService realService;
@Override
public void insert() {
if(realService==null) {
realService = new RealService();
}
System.out.println("action before");
realService.insert();
System.out.println("action after");
}
}
public class Client {
public static void main(String[] args) {
Service service = new Proxy();
service.insert();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment