Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class Entreprise {
- Map<String, Service> services = new HashMap<String, Service>();
- private static Entreprise instanceUnique = new Entreprise();
- private static IFactory factoryService;
- private Entreprise() {} //tous les constructeurs au niveau à private
- public static Entreprise getInstance(IFactory factory) {
- factoryService = factory;
- return instanceUnique;
- }
- public interface IFactory {
- Service creerService(String nom, String type);
- }
- public class Factory implements IFactory {
- @Override
- public Service creerService(String nom, String type) {
- if (type.equals("Administratif"))
- return new ServAdministratif(nom);
- else if (type.equals("Technique"))
- return new ServTechnique(nom);
- else
- throw new IllegalArgumentException ("type");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement