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

谁排第一

谁排第一

Amy N. Langville、Carl D. Meyer / 郭斯羽 / 机械工业出版社 / 2014-6 / 49

《谁排第一?关于评价和排序的科学》是首个关于评分和排名科学的著作。它是搜索排序姊妹篇的第二本。本书主要内容有:排名概述、梅西法、科利法、基纳法、埃洛体系、马尔可夫法、攻防评分法、基于重新排序的排名方法、分差、用户偏好评分、处理平局、加入权重、“假如……会怎样”的问题与敏感性、排名聚合、比较排名的方法、数据等。 《谁排第一?关于评价和排序的科学》可作为数学、计算机、网络技术、管理学和数据科学等......一起来看看 《谁排第一》 这本书的介绍吧!

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

在线压缩/解压 CSS 代码

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

在线XML、JSON转换工具

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

HSV CMYK互换工具