Created
March 23, 2018 02:48
-
-
Save alexvbush/6614a198b409ce462eb0ce93b5d875f8 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
import Foundation | |
protocol User { | |
var firstName: String { get } | |
var lastName: String { get } | |
func fullName() -> String | |
} | |
class CurrentUser: User { | |
let firstName: String | |
let lastName: String | |
init(firstName: String, lastName: String) { | |
self.firstName = firstName | |
self.lastName = lastName | |
} | |
func fullName() -> String { | |
return "\(firstName) \(lastName)" | |
} | |
} | |
class GuestUser: User { | |
var firstName = "Guest" | |
var lastName = "User" | |
func fullName() -> String { | |
return "\(firstName) \(lastName)" | |
} | |
} | |
class YourViewControllerOrSomeOtherPlace { | |
private let user: User | |
init(user: User) { | |
self.user = user | |
} | |
func viewDidLoadOrSomeOtherMethod() { | |
print("rendering UI for the user since we clearly have one, either current or guest") | |
print("user's full name is: \(user.fullName())") | |
} | |
} | |
let currentUser = CurrentUser(firstName: "Joe", lastName: "Dow") | |
let aVCWithAUser = YourViewControllerOrSomeOtherPlace(user: currentUser) | |
aVCWithAUser.viewDidLoadOrSomeOtherMethod() | |
print("=================") | |
let guestUser = GuestUser() | |
let aVCWithGuestUser = YourViewControllerOrSomeOtherPlace(user: guestUser) | |
aVCWithGuestUser.viewDidLoadOrSomeOtherMethod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment