Skip to content

Instantly share code, notes, and snippets.

@fitomad fitomad/se-0244_model.swift Secret
Created Jun 4, 2019

Embed
What would you like to do?
// 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
You can’t perform that action at this time.