일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Spring Boot
- 인텔리J
- 구마모토 백패킹
- elastic search
- Gradle
- 도메인주도설계
- nginx
- hadoop
- Linux
- 엘라스틱서치
- docker
- 스프링 배치
- SBT
- intellij
- Spring Batch
- hdfs
- Storm
- 일본 백패킹
- elasticsearch
- design pattern
- 제주
- scala
- Angular2
- Clean Code
- DDD
- Spring
- Spring XD
- Java
- Hbase
- apache storm
Archives
- Today
- Total
욱'S 노트
Command - 명령을 클래스로 표현하기 본문
반응형
When Using It
명령을 클래스로 표현하고 싶을때
Class Diagram
Sample Code
Caution
특별한 주의사항은 없다.
명령을 클래스로 표현하고 싶을때
Class Diagram
Sample Code
public interface Command {
public void execute();
}
public class ConcreteCommand implements Command {
private Receiver receiver = new Receiver();
@Override
public void execute() {
receiver.action();
}
}
public class Receiver {
public void action() {
System.out.println("Action Performed!!!");
}
}
public class Invoker {
private List<Command> commands = new ArrayList<Command>();
public void addCommand(Command command) {
commands.add(command);
}
public void excute() {
for ( Command command : commands) {
command.execute();
}
}
}
public class Client {
public static void main(String[] args) {
Invoker invoker = new Invoker();
invoker.addCommand(new ConcreteCommand());
invoker.excute();
}
}
Caution
특별한 주의사항은 없다.
반응형
'Methdology > Design Pattern' 카테고리의 다른 글
Intepreter - 언어로 문제를 해결하기 (0) | 2012.04.30 |
---|---|
State - 클래스로 상태 표현하기 (0) | 2012.04.27 |
Memento - 상태 저장하기 (0) | 2012.04.26 |
Observer - 자신의 상태를 전달하기 (2) | 2012.04.26 |
Mediator - 중개인을 통해 지시내리기 (1) | 2012.04.26 |