Skip to content

Instantly share code, notes, and snippets.

@Oni-zerone
Created December 10, 2018 17:00
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 Oni-zerone/2174b6c1f422d468313d468c272e8559 to your computer and use it in GitHub Desktop.
Save Oni-zerone/2174b6c1f422d468313d468c272e8559 to your computer and use it in GitHub Desktop.
open class Builder<Context> {
public init() { }
open func build(_ context: Context) -> UIViewController? {
return nil
}
}
public protocol AbstractFactory {
associatedtype Context
var context: Context { get }
func make(from builder: Builder<Context>) -> UIViewController?
func getBuilder(from builderContainer: BuilderContainer) -> Builder<Context>?
}
public extension AbstractFactory {
func make(from builder: Builder<Context>) -> UIViewController? {
return builder.build(self.context)
}
func getBuilder(from container: BuilderContainer) -> Builder<Context>? {
return container.getBuilder(Context.self)
}
}
public protocol BuilderContainer {
func getBuilder<Context>(_ contextType: Context.Type) -> Builder<Context>?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment