设计模式与软件原则 (六):适配器模式
2022-03-08 本文已影响0人
_浅墨_

适配器模式 Adapter Design Pattern
适配器是一种结构设计模式,用于链接原本彼此不兼容的实体。
一个简单的示例:
struct OldLocation {
var xPosition: Double
var yPosition: Double
}
struct NewLocation {
let oldLocation: OldLocation
var latitude: Double {
return oldLocation.xPosition
}
var longitude: Double {
return oldLocation.yPosition
}
}
let oldLocation = OldLocation(xPosition: 23.0, yPosition: 34.2)
let newLocation = NewLocation(oldLocation: oldLocation)