728x90 반응형 분류 전체보기826 2022-05-12-인터프리터패턴-1부-패턴소개 01.인터프리터패턴 정규 표현식 같은 것도 일종의 인터프리터 문서에서 어떤 문자를 찾는것 같은 , 키워드, 특정단어 ? 이런것 import java.util.Stack; public class PostfixNotation { private final String expression; public PostfixNotation(String expression) { this.expression = expression; } public static void main(String[] args) { PostfixNotation postfixNotation = new PostfixNotation("123+-"); postfixNotation.calculate(); } private void calculate() { .. 2022. 5. 12. 2022-05-11-커맨드패턴-3부-장점과단점 01.장점 기존의 코드 변경 없이 새로운 커맨드 만들 수 있음 변경에는 닫혀있고 확장에는 열려있음 수신자의 코드 즉, 게임이나 라이트 코드 바껴도 버튼이나 마이앱같은 요청하는 코드가 변경되지 않음 각각의 커맨드 자기 할일만 함 단일 책임원칙을 준수 커맨드 객체를 로깅, DB에 저장, 네트워크로 전송 하는 등 다양한 방법으로 활용할 수도 있음 01.1 undo 기능이 있다면? before public interface Command{ void execute(); } after public interface Command{ void execute(); void undo(); } before public class GameEndCommand implements Command{ private Game game;.. 2022. 5. 12. 2022-05-11-커맨드패턴-2부-패턴적용하기 01.커맨드 패턴 적용하기 01.1 Command public interface Command{ void execute(); } 01.2 Button public class Button{ private Command command; pulic Button(command command){ this.command = command; } public void press(){ command,execute(); } public static void main(String[] args){ Button button = new Button(new Command(){ @Override public void execute(){ } }); button.press(); button.press(); } } 02.Concreate.. 2022. 5. 12. 2022-05-11-커맨드패턴-1부-패턴소개 01.커맨드패턴 01.1 Button.java public class Button{ private Light light; public Button(Light light){ this.light = light; } public void press(){ light.on(); } public static void main(String[] args){ Button button = new Button(new Light()); button.press(); button.press(); button.press(); } } 01.2 Light.java public class Light{ private booleam isOn; public void on(){ System.out.println("불을 켭니다."); this... 2022. 5. 12. 이전 1 ··· 16 17 18 19 20 21 22 ··· 207 다음 728x90 반응형