细究设计模式
本文最后更新于 39 天前,其中的信息可能已经有所发展或是发生改变。

委托模式(Delegate)

class BarImpl // delegate 代表
class Foo { // delegator 委托者
  barImpl
  public Bar(){
    barImpl.Bar() // delegation 委派
  }
}

代理模式(Proxy)

class BarImpl
class Foo {
  barImpl
  public Bar() {
    print("begin bar") // 代理模式可以增加自己的逻辑
    barImpl.Bar()
    print("end bar")
  }
}

代理模式属于一种委托模式,代理模式可以增加自己的逻辑

组合模式(Composition)

class BarImpl
class Foo {
  children[]

  public Foo() {
    children = [new BarImpl()]
  }
  public Bar() {
    for child in children {
      child.Bar()
    }
  }
}

组合模式包含了多个委托代表,是 has many 的关系。组合模式下通常父对象拥有子对象的所有权,由父对象来控制子对象的生命周期。

暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇