Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save biloshkurskyi-ss/c11b94391a67ddf2b85f01e49b40cf42 to your computer and use it in GitHub Desktop.
Save biloshkurskyi-ss/c11b94391a67ddf2b85f01e49b40cf42 to your computer and use it in GitHub Desktop.
SWIFT.SOLID.DependencyInversion.Good
protocol VendorType {
func process(order: Order, success: () -> Void, failure: () -> Void)
}
class Administrator: VendorType {
func process(order: Order, success: () -> Void, failure: () -> Void) { /* process order */ }
}
class Seller: VendorType {
func process(order: Order, success: () -> Void, failure: () -> Void) { /* process order */ }
}
class StoreService {
let seller: VendorType
init(seller: VendorType) {
self.seller = seller
}
func fetch(order: Order, from customer: Customer, success: () -> Void, failure: () -> Void) {
//some bisness logic with order & customer requirements
seller.process(order: order, success: {
success()
}, failure: {
failure()
})
}
}
let storeService = StoreService(Administrator())
storeService.fetch(order: Order(), from: Customer(), success: {
/*order complited*/
}) {
/*process failure*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment