Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- executable jar
- design pattern
- v-model vs v-bind
- data
- IPv6
- camel case error
- vuejs
- mount point
- v-show vs v-if
- MVVM
- kebab case
- Linux
- click.native
- $event.target.value
- java
- Factory Method Pattern
- builder pattern
- zen of python
- ubuntu
- Python
- Singleton pattern
- Spring Boot
- maven
- prototype pattern
Archives
- Today
- Total
Eddie's Blog
[design pattern] Abstract Factory Pattern 본문
유형: 생성자 패턴
연관 혹은 의존 객체의 집합(families)을 생성하는데 있어서 그에 대한 구현 클래스를 특정하지 않고 인터페이스를 제공한다.
// abstract interface
public interface Animal {
String getAnimal();
String makeSound();
}
// concrete animal implementation
public class Cat implements Animal {
@Override
public String getAnimal() {
return "Cat";
}
@Override
public String makeSound() {
return "Meow";
}
}
public class Dog implements Animal {
@Override
public String getAnimal() {
return "Dog";
}
@Override
public String makeSound() {
return "Bow wow";
}
}
// abstract factory
public interface AbstractFactory<T> {
T create(String type);
}
// concrete factory implementation
public class AnimalFactory implements AbstractFactory<Animal> {
@Override
public Animal create(String type) {
if ("Dog".equalsIgnoreCase(type)) {
return new Dog();
} else if ("Cat".equalsIgnoreCase(type)) {
return new Cat();
}
return null;
}
}
public class FactoryProvider {
public static AbstractFactory getFactory(String factoryType) {
if ("Animal".equalsIgnoreCase(factoryType)) {
return new AnimalFactory();
} else if ("Color".equalsIgnoreCase(factoryType)) {
return new ColorFactory();//omitted color factory and its related objects
}
return null;
}
}
'programmings' 카테고리의 다른 글
[design pattern] Factory Method Pattern (0) | 2019.03.28 |
---|---|
[design pattern] Builder Pattern (0) | 2019.03.28 |
[spring boot] How to package a project with shell-executable jar (0) | 2019.02.11 |
[python] The Zen of Python, by Tim Peters (0) | 2018.06.13 |
[python] How to install latest python in Ubuntu (0) | 2018.06.13 |
Comments