Skip to content

Instantly share code, notes, and snippets.

View SamStone92's full-sized avatar

Sam Stone SamStone92

  • Gloucester, UK
View GitHub Profile
final class ProcessorUpgrade : MacBookDecorator {
override var cost: Double {
get {
return mbInstance.cost + 499
}
}
override var description: String {
get {
class MacBookDecorator : MacBook{
var cost: Double {
get {
return mbInstance.cost
}
}
var description: String {
get {
class MacBookAir : MacBook {
var cost: Double {
get {
return 999
}
}
var description: String {
get {
protocol MacBook {
var cost : Double { get }
var description : String { get }
}
print("Choose your starter Pokemon (B = Bulbasaur / C = Charmander / S = Squirtle)")
let response = readLine(strippingNewline: true)
let pokemon = PokemonFactory().getStarterPokemong(pokemonString: response!)
if pokemon != nil{
print("You have picked \((pokemon?.name)!). It is a \((pokemon?.type)!) Pokèmon")
} else {
print("Please pick a suitable Pokèmon")
class PokemonFactory{
func getStarterPokemong(pokemonString : String) -> Pokemon? {
switch pokemonString {
case "B":
return Bulbasaur()
case "C":
return Charmander()
case "S":
return Squirtle()
class Bulbasaur : Pokemon{
override init() {
super.init()
self.name = "Bulbasaur"
self.type = "Grass"
}
}
class Pokemon {
private var _name = String()
var name : String{
get{
return _name
}
set{
_name = newValue
}
let employee = Employee()
let boss = Boss()
let ceo = CEO()
employee.nextManagementLevel = boss
boss.nextManagementLevel = ceo
let expenditure = Expenditure(amount: 5)
employee.shouldApproveExpenditure(expenditure: expenditure)
let expenditure = Expenditure(amount: 5)
employee.shouldApproveExpenditure(expenditure: expenditure)
expenditure.amount = 500
employee.shouldApproveExpenditure(expenditure: expenditure)
expenditure.amount = 5000
employee.shouldApproveExpenditure(expenditure: expenditure)
expenditure.amount = 50000