added abstract factory example
This commit is contained in:
parent
2f41073a0f
commit
50e6ed18df
6
src/learn/simple_abstract_factory/AbstractFactory.java
Normal file
6
src/learn/simple_abstract_factory/AbstractFactory.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public interface AbstractFactory {
|
||||||
|
public AbstractProductA createProductA();
|
||||||
|
public AbstractProductB createProductB();
|
||||||
|
}
|
4
src/learn/simple_abstract_factory/AbstractProductA.java
Normal file
4
src/learn/simple_abstract_factory/AbstractProductA.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public interface AbstractProductA {
|
||||||
|
}
|
4
src/learn/simple_abstract_factory/AbstractProductB.java
Normal file
4
src/learn/simple_abstract_factory/AbstractProductB.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public interface AbstractProductB {
|
||||||
|
}
|
13
src/learn/simple_abstract_factory/ConcreteFactory1.java
Normal file
13
src/learn/simple_abstract_factory/ConcreteFactory1.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public class ConcreteFactory1 implements AbstractFactory {
|
||||||
|
@Override
|
||||||
|
public AbstractProductA createProductA() {
|
||||||
|
return new ProductA1();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractProductB createProductB() {
|
||||||
|
return new ProductB1();
|
||||||
|
}
|
||||||
|
}
|
13
src/learn/simple_abstract_factory/ConcreteFactory2.java
Normal file
13
src/learn/simple_abstract_factory/ConcreteFactory2.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public class ConcreteFactory2 implements AbstractFactory {
|
||||||
|
@Override
|
||||||
|
public AbstractProductA createProductA() {
|
||||||
|
return new ProductA2();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractProductB createProductB() {
|
||||||
|
return new ProductB2();
|
||||||
|
}
|
||||||
|
}
|
16
src/learn/simple_abstract_factory/Main.java
Normal file
16
src/learn/simple_abstract_factory/Main.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Client client1 = new Client(new ConcreteFactory1());
|
||||||
|
Client client2 = new Client(new ConcreteFactory1());
|
||||||
|
|
||||||
|
client1.setup();
|
||||||
|
|
||||||
|
client2.setAbstractFactory(new ConcreteFactory2());
|
||||||
|
client2.setup();
|
||||||
|
|
||||||
|
System.out.println(client1);
|
||||||
|
System.out.println(client2);
|
||||||
|
}
|
||||||
|
}
|
8
src/learn/simple_abstract_factory/ProductA1.java
Normal file
8
src/learn/simple_abstract_factory/ProductA1.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public class ProductA1 implements AbstractProductA {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ProductA1";
|
||||||
|
}
|
||||||
|
}
|
8
src/learn/simple_abstract_factory/ProductA2.java
Normal file
8
src/learn/simple_abstract_factory/ProductA2.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public class ProductA2 implements AbstractProductA {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ProductA2";
|
||||||
|
}
|
||||||
|
}
|
8
src/learn/simple_abstract_factory/ProductB1.java
Normal file
8
src/learn/simple_abstract_factory/ProductB1.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public class ProductB1 implements AbstractProductB {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ProductB1";
|
||||||
|
}
|
||||||
|
}
|
8
src/learn/simple_abstract_factory/ProductB2.java
Normal file
8
src/learn/simple_abstract_factory/ProductB2.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package learn.simple_abstract_factory;
|
||||||
|
|
||||||
|
public class ProductB2 implements AbstractProductB {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ProductB2";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user