Skip to content

Instantly share code, notes, and snippets.

@MostafaMazrouh
Created September 20, 2020 08:55
Show Gist options
  • Save MostafaMazrouh/614c4e948f612794d99db96a49ac1fe3 to your computer and use it in GitHub Desktop.
Save MostafaMazrouh/614c4e948f612794d99db96a49ac1fe3 to your computer and use it in GitHub Desktop.
Dependency Inversion vs Dependency Injection
class A {
var b: B
init(b: B) {
self.b = b
}
func start() {
b.doSomething()
}
}
class B {
func doSomething() {
}
}
protocol BInterface {
func doSomething()
}
class A {
var b: BInterface
init(b: BInterface) {
self.b = b
}
func start() {
b.doSomething()
}
}
class B: BInterface {
func doSomething() {
}
}
class C: BInterface {
func doSomething() {
}
}
class A {
var b: B
init() {
b = B()
}
func start() {
b.doSomething()
}
}
class B {
func doSomething() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment