forked from ochococo/Design-Patterns-In-Swift
-
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.
- Loading branch information
1 parent
10114a6
commit c0daff5
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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 @@ | ||
/*: | ||
📝 Template Method | ||
----------- | ||
|
||
The template method patter defines the steps of an algorithm and allows the redefinition of one or more of these steps. In this way, the template method protects the algorithm, the order of execution and provides abstract methods that can be implemented by concrete types. | ||
|
||
### Example | ||
*/ | ||
protocol Garden { | ||
func prepareSoil() | ||
func plantSeeds() | ||
func waterPlants() | ||
func prepareGarden() | ||
} | ||
|
||
extension Garden { | ||
|
||
func prepareGarden() { | ||
func prepareSoil() | ||
func plantSeeds() | ||
func waterPlants() | ||
} | ||
} | ||
|
||
final class RoseGarden: Garden { | ||
|
||
func prepare() { | ||
prepareGarden() | ||
} | ||
} | ||
|
||
/*: | ||
### Usage | ||
*/ | ||
|
||
let roseGarden = RoseGarden() | ||
roseGarden.prepare() |