Abstract Factory Pattern

This commit is contained in:
kim
2021-01-13 21:43:26 +09:00
parent bf5f1582d1
commit 922c2854e5
11 changed files with 94 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
Abstract Factory pattern
- 관련있는 객체 생성의 가상화

View File

@@ -0,0 +1,19 @@
package AbstractFactory;
import AbstractFactory.abst.BikeFactory;
import AbstractFactory.abst.Body;
import AbstractFactory.abst.Wheel;
import AbstractFactory.gt.GtBikeFactory;
import AbstractFactory.sam.SamFactory;
public class Main {
public static void main(String[] args) {
// BikeFactory factory = new SamFactory();
BikeFactory factory = new GtBikeFactory();
Body body = factory.createBody();
Wheel wheel = factory.createWheel();
System.out.println(body.getClass());
System.out.println(wheel.getClass());
}
}

View File

@@ -0,0 +1,7 @@
package AbstractFactory.abst;
public interface BikeFactory {
Body createBody();
Wheel createWheel();
}

View File

@@ -0,0 +1,4 @@
package AbstractFactory.abst;
public interface Body {
}

View File

@@ -0,0 +1,4 @@
package AbstractFactory.abst;
public interface Wheel {
}

View File

@@ -0,0 +1,17 @@
package AbstractFactory.gt;
import AbstractFactory.abst.BikeFactory;
import AbstractFactory.abst.Body;
import AbstractFactory.abst.Wheel;
public class GtBikeFactory implements BikeFactory {
@Override
public Body createBody() {
return new GtBody();
}
@Override
public Wheel createWheel() {
return new GtWheel();
}
}

View File

@@ -0,0 +1,6 @@
package AbstractFactory.gt;
import AbstractFactory.abst.Body;
public class GtBody implements Body {
}

View File

@@ -0,0 +1,6 @@
package AbstractFactory.gt;
import AbstractFactory.abst.Wheel;
public class GtWheel implements Wheel {
}

View File

@@ -0,0 +1,6 @@
package AbstractFactory.sam;
import AbstractFactory.abst.Body;
public class SamBody implements Body {
}

View File

@@ -0,0 +1,17 @@
package AbstractFactory.sam;
import AbstractFactory.abst.BikeFactory;
import AbstractFactory.abst.Body;
import AbstractFactory.abst.Wheel;
public class SamFactory implements BikeFactory {
@Override
public Body createBody() {
return new SamBody();
}
@Override
public Wheel createWheel() {
return new SamWheel();
}
}

View File

@@ -0,0 +1,6 @@
package AbstractFactory.sam;
import AbstractFactory.abst.Wheel;
public class SamWheel implements Wheel {
}