Created
March 31, 2018 09:59
-
-
Save iamcrypticcoder/44dd08f3eb32abf4f2aa9b9e30e7aa95 to your computer and use it in GitHub Desktop.
This file contains 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
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