<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Design Patterns常用設(shè)計模式示例

          聯(lián)合創(chuàng)作 · 2023-09-30 23:17

          Design Patterns 是如何使用常用設(shè)計模式及示例。

          示例:

          class MoneyPile {    let value: Int
              var quantity: Int
              var nextPile: MoneyPile?    init(value: Int, quantity: Int, nextPile: MoneyPile?) {        self.value = value        self.quantity = quantity        self.nextPile = nextPile
              }    func canWithdraw(var v: Int) -> Bool {        func canTakeSomeBill(want: Int) -> Bool {            return (want / self.value) > 0
                  }        var q = self.quantity        while canTakeSomeBill(v) {            if (q == 0) {                break
                      }
          
                      v -= self.value
                      q -= 1
                  }        if v == 0 {            return true
                  } else if let next = self.nextPile {            return next.canWithdraw(v)
                  }        return false
              }
          }class ATM {
              private var hundred: MoneyPile
              private var fifty: MoneyPile
              private var twenty: MoneyPile
              private var ten: MoneyPile
          
              private var startPile: MoneyPile {        return self.hundred
              }    init(hundred: MoneyPile, 
                     fifty: MoneyPile, 
                    twenty: MoneyPile, 
                       ten: MoneyPile) {        self.hundred = hundred        self.fifty = fifty        self.twenty = twenty        self.ten = ten
              }    func canWithdraw(value: Int) -> String {        return "Can withdraw: \(self.startPile.canWithdraw(value))"
              }
          }
          
          瀏覽 18
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  九哥操逼爱逼逼 | 91久久久久久国产 | 亚洲一级无码 | 亚洲黄色在线电影 | 婷婷五月开心五月 |