본문 바로가기
Computer Science

Facade pattern

by OKOK 2021. 7. 29.

Purpose

  • Supplies a single interface to a set of interfaces witin a system.

 

Use when

  • A simple interface is needed to provide access to a complex system.
  • There are many dependencies between system implementations and clients.
  • Systems and subsystems should be layered.
  • Provides a unified interface to a set of interfaces in a subsystem. It defines a higher-level interface that makes a subsystem easier to use

 

 

Motivation

  • In typical OO design,
    - Structuring a system into subsystems helps reduce complexity.

    - Subsystems are groups of classes, or groups of classes and other subsystems.
    - May produces many minimal classes

 

Benefits

  • Hides the implementation of the dsubsystem from clients
  • Promotes weak coupling between the subsystem and its clients.
  • Does not prevent sophisticated clients form accessing the underlying classes.
  • Facade does not add any functionality, it just simplifies interfaces.

 

Example

  • The app only knows and uses the high-level API when using the Db.

 

Comparing the Facade with the Adapter Pattern

  • Are there exisiting classes ? Facade : yes, Adapter : yes
  • Is there an interface we must design to? Facade : no, Adapter : yes
  • Is a simpler interface needed ? Facade : yes, Adapater : no

 

The Principle of Least Knowledge (Law of Demeter)

  • Talk only to your imediate friends

'Computer Science' 카테고리의 다른 글

Proxy Pattern  (0) 2021.07.30
Design Pattern Study  (0) 2021.07.29
Things to think about when designing a sofware structure  (0) 2021.07.29
Visitor Pattern  (0) 2021.07.29
Design Patter - Command Pattern  (0) 2021.07.29

댓글