Design Patterns/구조(Structural)

반응형
반응형
Design Patterns/구조(Structural)

[Proxy]프록시패턴

Proxy Pattern 특정 객체에 대한 접근을 제어하거나 기능을 추가할 수 있는 패턴 초기화 지연, 접근 제어, 로깅, 캐싱 등 다양하게 응용해 사용할 수 있다. 클라이언트가 원래 사용하려는 객체를 직접하는 하는 것이 아니라 '대리인'을 사용하여 접근하는 방식. BEFORE Client public class Client { public static void main(String[] args) throws InterruptedException { GameService gameService = new GameService(); gameService.startGame(); } } GameService public class GameService { public void startGame() { Syste..

Design Patterns/구조(Structural)

[Flyweight]플라이웨이트패턴

Flyweight Pattern 객체를 가볍게 만들어 메모리 사용을 줄이는 패턴 자주 변하는 속성(또는 외적인 속성, extrinsit)과 변하지 않는 속성(또는 내적인 속성, instrinsit)을 분리하고 재사용하여 메모리 사용을 줄일 수 있다. BEFORE Client - 현재 INTIP 웹 서비스에 게시판 에디터 부분이 아래처럼 되어 있는데, 해당 패턴을 활용하면 성능을 향상시킬 수 있겠다. public class Client { public static void main(String[] args) { Character c1 = new Character('h', "white", "Nanum", 12); Character c2 = new Character('e', "white", "Nanum", 1..

Design Patterns/구조(Structural)

[Facade]퍼사드패턴

Facade Pattern 복잡한 서브 시스템 의존성을 최소화하는 방법 클라이언트가 사용해야 하는 복잡한 서브 시스템 의존성을 간단한 인터페이스로 추상화 BEFORE Client - 기존의 클라이언트를 보면 발송정보, 메일 내용, 보내는 로직 등이 모두 하나의 코드에 의존적이다. public class Client { public static void main(String[] args) { String to = "keesun@whiteship.me"; String from = "whiteship@whiteship.me"; String host = "127.0.0.1"; Properties properties = System.getProperties(); properties.setProperty("mail..

Design Patterns/구조(Structural)

[Decorator]데코레이터패턴

Decorator Pattern 기존 코드를 변경하지 않고 부가 기능을 추가하는 패턴 상속이 아닌 위임을 사용해서 보다 유연하게 (런타임에) 부가 기능을 추가하는 것도 가능 기존 코드를 변경하지 않고 부가 기능을 추가하는 패턴 Client public class Client { private CommentService commentService; public Client(CommentService commentService) { this.commentService = commentService; } public void writeComment(String comment) { commentService.addComment(comment); } } CommentService public interface C..

Design Patterns/구조(Structural)

[Composite]컴포짓패턴

Composite Pattern 그룹 전체와 개별 객체를 동일하게 처리할 수 있는 패턴 클라이언트 입장에서 '전체'나 '부분'이나 모두 동일한 컴포넌트로 인식할 수 있는 계층 구조를 만든다(Part-Whole Hierarchy) 그룹 전체와 개별 객체를 동일하게 처리할 수 있는 패턴. Client - Item과 Bag은 Component를 상속받고 Client를 생성할 때 Component를 주입하여 해당 가격을 구한다. public class Client { public static void main(String[] args) { Item doranBlade = new Item("도란검", 450); Item healPotion = new Item("체력 물약", 50); Bag bag = new Ba..

Design Patterns/구조(Structural)

[Bridge]브릿지패턴

Bridge Pattern 추상적인 것과 구체적인 것을 분리하여 연결하는 패턴 하나의 계층 구조일 때 보다 각기 나누었을 때 독립적인 계층 구조로 발전 시킬 수 있다. Champion public interface Champion { void move(); void skillQ(); void skillW(); void skillE(); void skillR(); } DefaultChamPion public class DefaultChampion implements Champion { private Skin skin; private String name; public DefaultChampion(Skin skin, String name) { this.skin = skin; this.name = name; ..

emojiyeon
'Design Patterns/구조(Structural)' 카테고리의 글 목록