Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 对象适配器
- */
- // 适配者(原系统)
- public class Adaptee {
- public func oldFunc(text: String) {
- print(text)
- }
- }
- // 适配器
- public class Adapter: Target {
- private let adaptee = Adaptee()
- public func newFunc(num: Int) {
- adaptee.oldFunc(String(num))
- }
- }
- // 目标抽象
- public protocol Target {
- func newFunc(num: Int)
- }
- // 使用者
- let target = Adapter()
- target.newFunc(234)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement