Created
August 2, 2022 05:40
-
-
Save vinimonteiro/4357d3fd8d08a164ae99c01a7ffc7b2a to your computer and use it in GitHub Desktop.
Proxy dp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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