Skip to content

Instantly share code, notes, and snippets.

@iamcrypticcoder
Created March 31, 2018 09:59
Show Gist options
  • Save iamcrypticcoder/44dd08f3eb32abf4f2aa9b9e30e7aa95 to your computer and use it in GitHub Desktop.
Save iamcrypticcoder/44dd08f3eb32abf4f2aa9b9e30e7aa95 to your computer and use it in GitHub Desktop.
import Foundation
protocol Command {
func execute() -> Void
}
public class BuyCommand : Command {
let book: Book
init(_ book: Book) {
self.book = book
}
func execute() {
book.buy()
}
}
public class SellCommand : Command {
let book: Book
init(_ book: Book) {
self.book = book
}
func execute() {
book.sell()
}
}
public class GiftFriendCommand : Command {
let book: Book
let friendName: String
init(_ book: Book, _ friendName: String) {
self.book = book
self.friendName = friendName
}
func execute() {
book.giftToFriend(friendName)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment