-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
definitions for all of solid principles, more examples
- Loading branch information
1 parent
9617f3d
commit b9ca64b
Showing
26 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
...y Inversion Principle.playground/Pages/Worker and manager.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
|
||
//The Dependency Inversion Principle states that: | ||
///1. High-level modules should not depend on low-level modules. Both should depend on abstractions. | ||
///2. Abstractions should not depend upon details. Details should depend upon abstractions. | ||
|
||
protocol IWorker { | ||
|
||
func work() | ||
} | ||
|
||
class Worker: IWorker { //low-level | ||
|
||
func work() { | ||
|
||
} | ||
} | ||
|
||
class SuperWorker: IWorker { | ||
|
||
func work() { | ||
|
||
} | ||
} | ||
|
||
class Manager { //high-level | ||
|
||
var worker: IWorker! | ||
|
||
func setWoker(_ worker: IWorker) { | ||
self.worker = worker | ||
} | ||
|
||
func manage() { | ||
worker.work() | ||
} | ||
} |
7 changes: 5 additions & 2 deletions
7
...n Patterns in Swift/Solid/Dependency Inversion Principle.playground/contents.xcplayground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
<playground version='6.0' target-platform='ios'> | ||
<pages> | ||
<page name='Worker and manager'/> | ||
<page name='Relatioship example'/> | ||
</pages> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
...Dependency Inversion Principle.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...version Principle.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+10.6 KB
.../playground.xcworkspace/xcuserdata/hlazarpesic.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
4 changes: 3 additions & 1 deletion
4
Design Patterns in Swift/Solid/Interface Segregation Principle.playground/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...nterface Segregation Principle.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...egation Principle.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+9.25 KB
.../playground.xcworkspace/xcuserdata/hlazarpesic.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
3 changes: 2 additions & 1 deletion
3
Design Patterns in Swift/Solid/Liskov Substitution Principle.playground/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
.../Liskov Substitution Principle.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...itution Principle.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+9.24 KB
.../playground.xcworkspace/xcuserdata/hlazarpesic.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
...losed Principle.playground/Contents.swift → ...ification.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import UIKit | ||
import Foundation | ||
|
||
enum Color { | ||
|
||
|
49 changes: 49 additions & 0 deletions
49
...Swift/Solid/Open-Closed Principle.playground/Pages/Shapes.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Foundation | ||
|
||
//Software entities (classes, modules, functions, etc) should be open for extension, but closed for modification. | ||
|
||
protocol Shape { | ||
|
||
func getArea() -> Double | ||
} | ||
|
||
class Rectangle: Shape { | ||
|
||
var length: Double | ||
var height: Double | ||
|
||
init(_ length: Double, _ height: Double) { | ||
self.length = length | ||
self.height = height | ||
} | ||
|
||
func getArea() -> Double { | ||
return length * height | ||
} | ||
} | ||
|
||
class Circle { | ||
|
||
var radius: Double | ||
|
||
init(_ radius: Double) { | ||
self.radius = radius | ||
} | ||
|
||
func getArea() -> Double { | ||
return radius * radius * 3.14 | ||
} | ||
} | ||
|
||
class AreaManager { | ||
|
||
func calculateArea(shapes: [Shape]) -> Double { | ||
var area: Double = 0.0 | ||
|
||
for shape in shapes { | ||
area += shape.getArea() | ||
} | ||
|
||
return area | ||
} | ||
} |
7 changes: 5 additions & 2 deletions
7
Design Patterns in Swift/Solid/Open-Closed Principle.playground/contents.xcplayground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
<playground version='6.0' target-platform='ios'> | ||
<pages> | ||
<page name='Shapes'/> | ||
<page name='Filtering and Specification'/> | ||
</pages> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
...ft/Solid/Open-Closed Principle.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...-Closed Principle.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+13.9 KB
.../playground.xcworkspace/xcuserdata/hlazarpesic.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
3 changes: 2 additions & 1 deletion
3
Design Patterns in Swift/Solid/Single Responsibility Principle.playground/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ingle Responsibility Principle.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...ibility Principle.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+9.05 KB
.../playground.xcworkspace/xcuserdata/hlazarpesic.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.