常用设计模式示例 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

Paradigms of Artificial Intelligence Programming

Paradigms of Artificial Intelligence Programming

Peter Norvig / Morgan Kaufmann / 1991-10-01 / USD 77.95

Paradigms of AI Programming is the first text to teach advanced Common Lisp techniques in the context of building major AI systems. By reconstructing authentic, complex AI programs using state-of-the-......一起来看看 《Paradigms of Artificial Intelligence Programming》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

URL 编码/解码
URL 编码/解码

URL 编码/解码