Adapter Pattern

Adapter Pattern

Motivation

  • μ–΄λŒ‘ν„° νŒ¨ν„΄μ€ ν΄λž˜μŠ€μ™€ κ°μ²΄κ°„μ˜ μ–΄λŒ‘νŒ…μž„
  • 리얼 μ›”λ“œμ—μ„œμ˜ μ–΄λŒ‘ν„° 처럼 μ–΄λŒ‘ν„°λŠ” μΈν„°νŽ˜μ΄μŠ€ λ‘œμ„œ 두 객체λ₯Ό 연결함
  • λ©”λͺ¨λ¦¬ μΉ΄λ“œλ₯Ό 컴퓨터에 λ°”λ‘œ λͺ» 꼽으면? 쀑간에 μ–΄λŒ‘ν„°λ₯Ό μ“°μž!
  • 두 객체λ₯Ό μ—°κ²°ν•΄ μ“°κ³  μ‹ΆμœΌλ©΄? 쀑간에 μ–΄λŒ‘ν„°λ₯Ό μ“°μž!

Intent

  • 클래슀의 μΈν„°νŽ˜μ΄μŠ€λ₯Ό ν΄λΌμ΄μ–ΈνŠΈκ°€ μ‚¬μš©ν•  수 μžˆλŠ” μΈν„°νŽ˜μ΄μŠ€λ‘œ λ°”κΏ”μ£Όμž.
  • μ–΄λŒ‘ν„°λŠ” μΈν„°νŽ˜μ΄μŠ€κ°€ 달라 work together ν•  수 μ—†λŠ” ν΄λž˜μŠ€λ“€μ„ work togetherν•˜κ²Œ ν•΄μ€Œ.

Implementation

notion image
  • νƒ€κ²Ÿ= μ»΄ν“¨ν„°μ˜ USB ꡬ멍
  • μ–΄λŽν„° = μ–΄λŽν„°
  • μ–΄λŽν‹° = λ©”λͺ¨λ¦¬μΉ΄λ“œ
  • ν΄λΌμ΄μ–ΈνŠΈ = λ‚˜

Applicablity

μ΄λŸ΄λ•Œ μ–΄λŽν„° νŒ¨ν„΄μ„ μ“°μž
  • 두 클래슀λ₯Ό μ—°κ²°ν•˜κ³  μ‹Άμ„λ•Œ

Examples

  • Wrapper 클래슀
 

Specific problems & Implementation

 
Object Adapters - Based on Delegation
Class Adaptors - Based on (multiple) Inheritance
notion image
 
μ–΄λŒ‘ν„° νŒ¨ν„΄ + μ „λž΅ νŒ¨ν„΄
같은 클래슀λ₯Ό μ—°κ²°ν•˜λŠ” μ–΄λŒ‘ν„°λ₯Ό μ—¬λŸ¬λ°©μ‹μœΌλ‘œ μ œκ³΅ν•΄μ„œ μ „λž΅ νŒ¨ν„΄μ— 따라 κ°ˆμ•„ 끼울 수 μžˆλ‹€.