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
final class ProcessorUpgrade : MacBookDecorator { | |
override var cost: Double { | |
get { | |
return mbInstance.cost + 499 | |
} | |
} | |
override var description: String { | |
get { |
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 MacBookDecorator : MacBook{ | |
var cost: Double { | |
get { | |
return mbInstance.cost | |
} | |
} | |
var description: String { | |
get { |
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 MacBookAir : MacBook { | |
var cost: Double { | |
get { | |
return 999 | |
} | |
} | |
var description: String { | |
get { |
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
protocol MacBook { | |
var cost : Double { get } | |
var description : String { get } | |
} |
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
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") |
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 PokemonFactory{ | |
func getStarterPokemong(pokemonString : String) -> Pokemon? { | |
switch pokemonString { | |
case "B": | |
return Bulbasaur() | |
case "C": | |
return Charmander() | |
case "S": | |
return Squirtle() |
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 Bulbasaur : Pokemon{ | |
override init() { | |
super.init() | |
self.name = "Bulbasaur" | |
self.type = "Grass" | |
} | |
} |
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 Pokemon { | |
private var _name = String() | |
var name : String{ | |
get{ | |
return _name | |
} | |
set{ | |
_name = newValue | |
} |
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
let employee = Employee() | |
let boss = Boss() | |
let ceo = CEO() | |
employee.nextManagementLevel = boss | |
boss.nextManagementLevel = ceo | |
let expenditure = Expenditure(amount: 5) | |
employee.shouldApproveExpenditure(expenditure: expenditure) |
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
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 |