Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. public final class Entreprise {
  2.     Map<String, Service> services = new HashMap<String, Service>();
  3.     private static Entreprise instanceUnique = new Entreprise();
  4.     private static IFactory factoryService;
  5.     private Entreprise() {} //tous les constructeurs au niveau à private
  6.    
  7.     public static Entreprise getInstance(IFactory factory) {
  8.         factoryService = factory;
  9.         return instanceUnique;
  10.     }
  11. public interface IFactory {
  12.     Service creerService(String nom, String type);
  13. }
  14.  
  15. public class Factory implements IFactory {
  16.  
  17.     @Override
  18.     public Service creerService(String nom, String type) {
  19.         if (type.equals("Administratif"))
  20.             return new ServAdministratif(nom);
  21.         else if (type.equals("Technique"))
  22.             return new ServTechnique(nom);
  23.         else
  24.             throw new IllegalArgumentException ("type");   
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement