Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. /*
  2. 对象适配器
  3. */
  4. // 适配者(原系统)
  5. public class Adaptee {
  6. public func oldFunc(text: String) {
  7. print(text)
  8. }
  9. }
  10.  
  11. // 适配器
  12. public class Adapter: Target {
  13. private let adaptee = Adaptee()
  14.  
  15. public func newFunc(num: Int) {
  16. adaptee.oldFunc(String(num))
  17. }
  18. }
  19.  
  20. // 目标抽象
  21. public protocol Target {
  22. func newFunc(num: Int)
  23. }
  24.  
  25. // 使用者
  26. let target = Adapter()
  27. target.newFunc(234)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement