composition5 Decorator Pattern - 구조, 구성과 위임을 통해 특정 개체에 행동을 동적으로 추가 | [Design pattern] 디자인 패턴 Decorator Pattern 같은 class의 다른 객체들에는 영향을 주지 않고, 구성과 위임을 통해 특정 객체에 행동을 동적으로 추가 소스를 변경하지 않고 기능을 확장 기존 객체의 메소드에 새로운 행동을 추가하거나 오버라이딩 가능 객체에 독립적인 기능을 계속해서 추가, 확장할 때 유용 객체에 부가적인 기능을 동적으로 추가할 때 사용 문제점) 상속을 사용한 객체의 기능 확장은 subclass를 양산한다. Subclassing을 사용한 정적 확장의 문제점: ① 너무 많은 subclass가 필요함 ② 새로운 유형의 음료수가 개발될 때마다 subclass를 계속 추가되어야 함. 패턴 아이디어) DataInputStream dis; // primitive value dis = new DataInputStre.. 2021. 12. 11. Composite Pattern Example code, Designing Menus with Composite .java | Design Pattern디자인 패턴 Designing Menus with Composite Waitress Waitress는 MenuComponent 인터페이스/추상 클래스 를 통해 Menu 와 Menuitems에 access 한다. MenuComponent Menu 와 MenuItem 의 interface를 나타낸다. abstract class 를 통해 클래스 내에 원하는 기본 메소드 구현 제공 공통연산과 Menu 조작 연산으로 구성 공통연산 : getName, getDescription, getPrice, print 조작연산 : add, remove, getChild MenuItem Both Menu and Menus override print() Menu we’ll use the getName() andngetDescription().. 2021. 10. 27. Composite Pattern - 구조, 개별 객체와 복합객체를 통합적으로 다루기, children의 저장 순서가 요구될 때 / ex) 메뉴 | Design Pattern 디자인 패턴 Composite Pattern Treat individual objects and Composite of objects uniformly. 개별 객체와 복합 객체를 클라이언트에서 동일하게 사용 child가 parent에 대한 참조자를 가지면 - tree traversal이 용이해지며 - child 자신이 제거되기를 원하는 경우 편리함 children의 저장 순서가 요구되는 경우 Composite Object (복합 객체) 사용자 정의 클래스를 도메인으로 하는 속성을 가진 객체 복합 객체 시스템에서 기본으로 제공하지 않는 사용자 정의 클래스(user-defined class)를 도메인으로 하는 속성을 가진 객체를 복합 객체(composite object)라 한다. 복합 객체에서 사용자 정의 클래스를 도메.. 2021. 10. 14. Adapter 어댑터 패턴 - 구조, client 가 요구하는 인터페이스와 제공된 클래스의 인터페이스가 일치하지 않을 때 | Design Pattern 디자인 패턴 구조에 따른 패턴 분류 적용 범위 Scope 클래스 class - 클래스 간 관계 - 주로 inheritance 사용 - 정적) 컴파일 시 결정됨 Adapter (class) (상속) 객체 object - 객체 간 관계 - 주로 composition 사용 - 동적) 실행 시 변경 가능 Adapter (object) (구성) Facade (퍼사드) Composite Decorator Proxy Bridge Flyweight 인터페이스 관련 패턴 • Adapter pattern • Facade pattern • Composite pattern • Bridge pattern ※ 모두 구조 패턴에 속함 Adapter 구조 패턴 언제 ? -> Interface mismatching client 가 요구하는 인터페.. 2021. 10. 10. [Design Pattern] 디자인 패턴 / UML Base .java 2021.09 디자인 패턴 강의 정리 UML A standard language for writing software blueprints 어휘 (Vocabularies) 세 종류의 Building block 으로 구성된다. - Things , Relationships, Diagrams Things Structural things 모델의 정적 부분 (개념적 요소)을 나타냄 interface, class, Behavioral things 모델의 동적 부분 (행동)을 나타냄 interaction (객체간 messaging), Grouping things organizational part package and its variations Annotational things explanatory part note.. 2021. 9. 11. 이전 1 다음