Work & Programming/System Design

[Structural Pattern] - Facade

자전거통학 2024. 5. 15. 10:32

https://refactoring.guru/design-patterns/facade

 

Facade

Intent Facade is a structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of classes. Problem Imagine that you must make your code work with a broad set of objects that belong to a sophisticated

refactoring.guru

 

하나의 객체가 다른 여러개의 객체의 조합으로 이루어 지고, 이를 통해 관련 구현을 하고자 할 때. 

 => 작은 모듈로 구성된 대부분의 독립 객체 구현시 사용.

 

예시 

 - Flight - Wing, Tail, Body 로 구성

 

예시 코드

더보기
class Wing
{
    public void Fly() { }
}
class Head
{
    public void Fly() { }
}
class Tail
{
    public void Fly() { }
}

class Flight
{
    Wing _wing;
    Head _head;
    Tail _tail;

    public Flight(Wing wing, Head head, Tail tail) {}
    public void Fly()
    {
        _wing.Fly();
        _head.Fly();
        _tail.Fly();
    }
}


internal class FacadeDemo
{
    public void Run()
    {
        Flight myFlight = new Flight(new Wing(), new Head(), new Tail());
        myFlight.Fly();
    }
}

'Work & Programming > System Design' 카테고리의 다른 글

[Structural Pattern] - Proxy  (0) 2024.05.15
[Structural Pattern] - Flyweight  (0) 2024.05.15
[Structural Pattern] - Decorator  (0) 2024.05.15
[Structural Pattern] - Composite  (0) 2024.05.15
[Structural Pattern] - Adapter  (0) 2024.05.15