Skip to main content
edited body
Source Link
Spotted
  • 1.7k
  • 10
  • 18

You can add another layer at the factory layerlevel:

public interface IUsers { ... }
public interface IFoo { ... }

public interface Factory {
    IUsers GetUsers();
    IFoo GetFoo();
}

public class MySQLFactory : Factory {
    public IUsers GetUsers() {
        return new MySQLUsers();
    }

    public IFoo GetFoo() {
        return new MySQLFoo();
    }
}

public class PostgresFactory : Factory {
    public IUsers GetUsers() {
        return new PostgresUsers();
    }

    public IFoo GetFoo() {
        return new PostgresFoo();
    }
}

public class DBFactory {
    public static Factory getFactory(bool something) {
        if(something) {
            return new MySQLFactory();
        }
        else {
            return new PostgresFactory();
        }
    }
}

You can add another layer at the factory layer:

public interface IUsers { ... }
public interface IFoo { ... }

public interface Factory {
    IUsers GetUsers();
    IFoo GetFoo();
}

public class MySQLFactory : Factory {
    public IUsers GetUsers() {
        return new MySQLUsers();
    }

    public IFoo GetFoo() {
        return new MySQLFoo();
    }
}

public class PostgresFactory : Factory {
    public IUsers GetUsers() {
        return new PostgresUsers();
    }

    public IFoo GetFoo() {
        return new PostgresFoo();
    }
}

public class DBFactory {
    public static Factory getFactory(bool something) {
        if(something) {
            return new MySQLFactory();
        }
        else {
            return new PostgresFactory();
        }
    }
}

You can add another layer at the factory level:

public interface IUsers { ... }
public interface IFoo { ... }

public interface Factory {
    IUsers GetUsers();
    IFoo GetFoo();
}

public class MySQLFactory : Factory {
    public IUsers GetUsers() {
        return new MySQLUsers();
    }

    public IFoo GetFoo() {
        return new MySQLFoo();
    }
}

public class PostgresFactory : Factory {
    public IUsers GetUsers() {
        return new PostgresUsers();
    }

    public IFoo GetFoo() {
        return new PostgresFoo();
    }
}

public class DBFactory {
    public static Factory getFactory(bool something) {
        if(something) {
            return new MySQLFactory();
        }
        else {
            return new PostgresFactory();
        }
    }
}
Source Link
Spotted
  • 1.7k
  • 10
  • 18

You can add another layer at the factory layer:

public interface IUsers { ... }
public interface IFoo { ... }

public interface Factory {
    IUsers GetUsers();
    IFoo GetFoo();
}

public class MySQLFactory : Factory {
    public IUsers GetUsers() {
        return new MySQLUsers();
    }

    public IFoo GetFoo() {
        return new MySQLFoo();
    }
}

public class PostgresFactory : Factory {
    public IUsers GetUsers() {
        return new PostgresUsers();
    }

    public IFoo GetFoo() {
        return new PostgresFoo();
    }
}

public class DBFactory {
    public static Factory getFactory(bool something) {
        if(something) {
            return new MySQLFactory();
        }
        else {
            return new PostgresFactory();
        }
    }
}