Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created June 4, 2019 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/33e4f1284820185a1806b04a452caabd to your computer and use it in GitHub Desktop.
Save fitomad/33e4f1284820185a1806b04a452caabd to your computer and use it in GitHub Desktop.
// 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