본문 바로가기
반응형

Spring/DesighPattern13

GOF패턴 - Visitor Pattern(행위) Visitor Pattern : 방문자 패턴을 이용해 객체(클래스) 에서 처리(메소드)와 분리해서 사용한다. VisitableElemenr 는 visitor 를 받아들이는 메소드만 구현함 (간단) public interface Visitor { public void visit(Visitable visitable); } public interface Visitable { public void accept(Visitor visitor); } visitor 는 방문 해야하고 visitorable visitor 를 accpet 해야함. public class VisitableA implements Visitable { int numberOfMember; public VisitableA(int numberOfMe.. 2023. 3. 22.
GOF패턴 - Decorator(구조) Decorator : 동적으로 책임추가가 필요할때 데코레이터 패턴 사용 Component : 실질적인 인스턴스를 컨트롤 하는 역할 >> 데코레이터와 컨크리트를 컨트롤한다 ConcreteComponent : Component 의 실직적인 인스턴스 부분 책임의주체 역할 Component 가 컨트롤 하는 객체 책임구현 실체화 Decorator : Component 와 Concrete Decorator 를 동일시 하도록 해주는 역할 Component가 되면서 가지고 있다. Concrete Decorator : 실질적인 장식 인스턴스이며 추가된 책임의 주체 부분 package DecoratorPattern.abst; public interface IBeverage { // 총 가격에 대해 책임을 묻는 부분 int.. 2023. 3. 22.
GOF패턴 - CompositePattern(구조) CompositePattern 트리 구조 구현 컨테이너(그릇) 내용물(객체) 동일시(패턴) 컴포지트란 OOP 에서 컴포지트(Composite) 는 하나 이상의 유사한 객체를 구성으로 설계된 객체로 모두 유사한 기능을 나타낸다. 이를 통해 객체 그룹을 조작하는 것처럼, 단일 객체를 조작할 수 있다. 복합 객체(group of object) 나 단일 객체를 동일하게 취급하는 것을 목적으로 한다. 여기서 컴포지트의 의도는 트리 구조로 작성하여, 전체부분 관계를 표현하는 것이다. >> 오브젝트 들을 트리구조로 한다 Component 동일시하게 만들어주는 인터페이스 역할을 해줄 설계 (abstract) leaf 상속받은 내용물 (상속을 받은 객체) composite -leaf들을 담음 / 그릇 (상속을 받는 그룹.. 2023. 3. 22.
GOF패턴 - BridgePattern(구조) BridgePattern 어댑터 패턴과 연결해서 이해해야한다. 멤버변수를 통해서 기능을 동작하는 패턴 기능부분만 바꾼다. dafult, sound Abstraction implemetor refindAbstraction concretImplementor package Bridge1; public class Main { public static void main(String[] args) { PrintMoresCode code = new PrintMoresCode(new SoundMCF()); // code.g();code.a();code.r();code.a();code.m(); code.g().a().r().a().m(); // 체이닝 } } package Bridge1; //abstraction 기능부.. 2023. 2. 24.
GOF패턴-AbstractFactoryPattern AbstractFactoryPattern 관련 있는 객체의 생성을 가상화한다. factory 부분을 가상화 / client 가상화된 product를 가지고 활용하는 패턴 팩토리 메서드 패턴은 실제 팩토리를 구현하는 인스턴스를 만들 때 상위 클래스를 확장하고 팩토리 메서드를 오버라이드 하여 상속을 통해 인스턴스를 생성하였다. 하지만 추상 팩토리 패턴은 AbstractFactory를 Interface 타입으로 생성하고 그 인터페이스를 실체화하여 객체를 생성하는 것이다. Button, Text > AbstractProdct GuiFactory = > 실제생성해야 할 Product ~~~GuiFac => ConcreateFactory AbstractProduct를 구현한 각 운영체제의 button, text인 .. 2023. 2. 23.
GOF패턴-BuilderPattern-2(생성) 많은 변수를 가진 객체의 생성을 가독성 높게한다. 많은 인자를 가진 객체를 생성을 다른 객체의 도움으로 생성하는 패턴 > 보통 빌더패턴이 이것이다. package Builder2; public class Main { public static void main(String[] args) { Computer computer = ComputerBuilder .start() .setCpu("i7") .setRam("8g") .setStorage("128g ssd") .build(); System.out.println("computer = " + computer.toString()); System.out.println("computer = " + computer); } } package Builder2; //디렉.. 2023. 2. 23.
반응형