[디자인패턴] Adapter 패턴

Adapter Pattern 한 클래스의 인터페이스를 클라이언트에서 사용하고자하는 다른 인터페이스로 변환한다.어댑터를 이용하면 인터페이스 호환성 문제 때문에 같이 쓸 수 없는 클래스들을 연결해서 쓸 수 있다.코드 출처: https://refactoring.guru/design-patterns/adapter/go/example 윈도우에는 USB, 맥북에는 thunderbolt 포트가 있다.윈도우 PC에 thunderbolt포트를 연결하기 위해 adapter가 필요하다client.go package main import "fmt" type client struct { } func (c *client) insertLightningConnectorIntoComputer(com computer) { fmt.Println("Client inserts Lightning connector into computer.") com.insertIntoLightningPort() } computer.go package main type computer interface { insertIntoLightningPort() } mac....

April 18, 2021 · 1 min · icecat471