-
-
Save fitomad/33e4f1284820185a1806b04a452caabd 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
// MARK: - A generic device - | |
public protocol Device | |
{ | |
var name: String { get } | |
} | |
// MARK: - The iPhone - | |
public struct iPhone: Device | |
{ | |
private let model = "XR" | |
public var name: String | |
{ | |
return "iPhone" | |
} | |
} | |
extension iPhone: Equatable | |
{ | |
public static func == (lhs: iPhone, rhs: iPhone) -> Bool | |
{ | |
return (lhs.name == rhs.name) && (lhs.model == rhs.model) | |
} | |
} | |
// MARK: - The Mac - | |
public struct Mac: Device | |
{ | |
private let model = 2015 | |
public var name: String | |
{ | |
return "MacBook Air" | |
} | |
} | |
extension Mac: Equatable | |
{ | |
public static func == (lhs: Mac, rhs: Mac) -> Bool | |
{ | |
return (lhs.name == rhs.name) && (lhs.model == rhs.model) | |
} | |
} | |
// MARK: - The Factory - | |
public struct AppleFactory | |
{ | |
/// A new Mac | |
public static func makeMac() -> some Equatable | |
{ | |
return Mac() | |
} | |
/// A new iPhone | |
public static func makePhone() -> some Equatable | |
{ | |
return iPhone() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment