常用设计模式示例 Design Patterns

码农软件 · 软件分类 · 其他开发相关 · 2019-10-21 13:12:17

软件介绍

Design Patterns 是如何使用常用设计模式及示例。

示例:

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))"
    }
}


本文地址:https://codercto.com/soft/d/17241.html

程式之美-微軟技術面試心得

程式之美-微軟技術面試心得

編程之美小 / 悅知文化 / 2008.06.20 / 490元

書內容分為以下幾個部分: ▓ 遊戲之樂:從遊戲和其他有趣問題出發,化繁為簡,分析總結。 ▓ 數字之魅:程式設計的過程實際上就是和數字及字元打交道的過程。這一部分收集了一些這方面的有趣探討。 ▓ 結構之法:彙集了常見的對字串、鏈表、佇列,以及樹進行操作的題目。 ▓ 數學之趣:列舉了一些不需要寫具體程式的數學問題,鍛煉讀者的抽象思考能力。 ▓ 書中絕大部分題目都提供了詳細......一起来看看 《程式之美-微軟技術面試心得》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具