Created
October 17, 2015 06:51
-
-
Save takaheraw/bcce4f9c629ef0518915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product { | |
var name:String | |
var price:Double | |
private var stockBackingValue:Int = 0 | |
var stock:Int { | |
get { | |
return stockBackingValue | |
} | |
set { | |
stockBackingValue = max(0, newValue) | |
} | |
} | |
init(name:String, price:Double, stock:Int) { | |
self.name = name | |
self.price = price | |
self.stock = stock | |
} | |
func calculateTax(rate: Double) -> Double { | |
return min(10, self.price * rate) | |
} | |
var stockValue: Double { | |
get { | |
return self.price * Double(self.stock) | |
} | |
} | |
} | |
let product = Product(name: "hoge", price: 1000.0, stock: 200) | |
product.stockValue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment