Skip to content

Instantly share code, notes, and snippets.

@anirudh83
Last active April 30, 2020 12:45
Show Gist options
  • Save anirudh83/745ca9d4c2e8161e8957 to your computer and use it in GitHub Desktop.
Save anirudh83/745ca9d4c2e8161e8957 to your computer and use it in GitHub Desktop.
public class EndpointA {
private UserService userService;
private AService aService;
/*constructor */
public EndpointA(UserService userService,AService aService){
this.userService = userService;
this.aService= aService;
}
}
public class EndpointB {
private UserService userService;
/*constructor */
public EndpointB(UserService userService){
this.userService = userService;
}
}
public class UserServiceImpl implements UserService {
private static final _INSTANCE = new UserServiceImpl();
public static UserService getInstance(){
return _INSTANCE;
}
private UserServiceImpl(){}
}
public class AServiceImpl implements AService {
private static final _INSTANCE = new AServiceImpl();
public static AService getInstance(){
return _INSTANCE;
}
private AServiceImpl(){}
}
public class EndpointFactory{
public EndpointA createEndpointA(){
return new EndpointA(UserService.getInstance(),AService.getInstance());
}
public EndpointB createEndpointB(){
return new EndpointB(UserService.getInstance());
}
}
public class Test{
@Test
public void init(){
EndpointFactory endpointFactory = new EndpointFactory();
EndpointA endpointA = endpointFactory.createEndpointA();
EndpointB endpointb = endpointFactory.createEndpointB();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment