Skip to content

Commit

Permalink
added Dependency Inversion playground and updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Boldt committed Mar 19, 2018
1 parent 7682b0f commit 91ece77
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 38 deletions.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
79 changes: 51 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,64 @@

### Behavioral

* ✅ Chain Of Responsibility
* ✅ Command
* ✅ Iterator
* ✅ Strategy
* ✅ Mediator
* ✅ Visitor
* ✅ Observer
* ✅ Memento
* ✅ State
* ❌ Interpreter
✅ Chain Of Responsibility

✅ Command

✅ Iterator

✅ Strategy

✅ Mediator

✅ Visitor

✅ Observer

✅ Memento

✅ State

❌ Interpreter

### Creational

* ✅ Singleton
* ✅ Prototype
* ✅ Factory Method
* ✅ Builder
* ✅ Abstract Factory
✅ Singleton

✅ Prototype

✅ Factory Method

✅ Builder

✅ Abstract Factory

### Structural

* ✅ Bridge
* ✅ Decorator
* ✅ Composite
* ✅ Adapter
* ✅ Flyweight
* ✅ Facade
* ✅ Protection Proxy
* ✅ Virtual Proxy
✅ Bridge

✅ Decorator

✅ Composite

✅ Adapter

✅ Flyweight

✅ Facade

✅ Protection Proxy

✅ Virtual Proxy

## S.O.L.I.D

* ❌ Single Responsibilty Principle (SRP)
* ❌ Open Closed Principle (OCP)
* ❌ Liskov Substitution Principle (LSP)
* ❌ Interface Segregation Principle (ISP)
* ❌ Dependency Inversion Principle (DIP)
✅ Dependency Inversion Principle (DIP)

❌ Single Responsibilty Principle (SRP)

❌ Open Closed Principle (OCP)

❌ Liskov Substitution Principle (LSP)

❌ Interface Segregation Principle (ISP)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//: [Previous](@previous)

import Foundation

// The Problem - Tightly coupled classes

struct Wrong {
struct Datastore {
// The Datastore should not know something about the Filehandler, it should use an abstraction instead
let fileHandler: FileHandler = FileHandler()
}

struct FileHandler {
func getFile(name: String) -> Data {
return Data()
}

func storeFile(name: String, data: Data) {
// Stores the File
}
}
}


// The Solution - Protocols and DI through the initalizer

protocol FileHandlerProtocol {
func getFile(name: String) -> Data
func storeFile(name: String, data: Data)
}

struct Right {
struct Datastore {
let fileHandler: FileHandlerProtocol

init(fileHandler: FileHandlerProtocol) {
self.fileHandler = fileHandler
}
}

struct FileHandler: FileHandlerProtocol {
func getFile(name: String) -> Data {
return Data()
}
func storeFile(name: String, data: Data) {
// Store the File
}
}
}


//: [Next](@next)
4 changes: 1 addition & 3 deletions SOLID.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
<playground version='6.0' target-platform='ios'/>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

0 comments on commit 91ece77

Please sign in to comment.