8. Observer 문제구현 상속 기반의 해결안abstract class BadJMenuItem {abstract void itemSelected();}classMyMenuItemextendsBadJMenuItem {public void itemSelected() {//아이템이 선택되었을 때 수행할 것... }}문제점
14. Observer: 멀티스레드 환경 4불변 객체 노드를 사용하는 리스트 해결법이전:헤드d:Objectc:Objectb:Objecta:Object이후:가비지 컬렉션 될 것임이전 헤드d:Objectc:Objectb:Objecta:Object헤드
15. class GoF_VisitorVisitor+ VisitConcreteElementA(ConcreteElementA)+ VisitConcreteElementB(ConcreteElementB)ConcreteVisitor1ConcreteVisitor2+ VisitConcreteElementA(ConcreteElementA)+ VisitConcreteElementA(ConcreteElementA)+ VisitConcreteElementB(ConcreteElementB)+ VisitConcreteElementB(ConcreteElementB)ElementObjectStructure1..*+ Accept(Visitor)ConcreteElementAConcreteElementB+ Accept(Visitor)+ Accept(Visitor)v->VisitConcreteElementA(this)v->VisitConcreteElementB(this)GoF– Visitor Pattern의도기존 계층 구조를 수정하지 않고 새로운 메소드를 추가하고자 할 때전문가 도입
19. class GoF_CompositeComponent1..*+ Operation()Client+ Add() : Component+ Remove() : Component+ GetChild() : ComponentLeafComposite+ Operation()+ Operation()-childrenforall g in children g.Operation();+ Add() : Component+ Remove() : Component+ GetChild() : ComponentGoF – Composite Pattern의도개별 객체와 복합 객체를 동일하게 다루고 싶을 경우
20. class AWT_ComponentContainerpublic void doLayout(){Component for( every Component in contents ) doLayout();+ doLayout() : void}0..*1ComponentContainer+ doLayout() : voidButtonLeaf+ add(Component) : ComponentCompositeCheckboxLeafCompositeCompositeWindowCompositeLeafChoiceFrameCompositeDialogCase Study: AWT Component/Container
21. 패턴은 변형되어 실체화된다Composite 패턴의 의도를 보라class Directory SystemLeaf and ComponentSimpleFileComposite+ open()+ close()Composite+ print()Directorypublic void print()0..*{{contents}+ print() for(int i=0; i < contents.length; ++i)+ add(SimpleFile) contents[i].print();1+ remove(SimpleFile)}+ contents() : IteratorCase Study: Directory System