-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template Method #18
base: main
Are you sure you want to change the base?
Template Method #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments as if we come back to the pattern these comments will be useful. But as discussed, let's park this pattern for now.
- The Template Method pattern starts with defining a protocol listing steps in a sequence of operations we would like to perform. | ||
|
||
- We then provide a default implementation for each step in the sequence, as well as define the method that orchestrates the sequence. | ||
|
||
- Subclasses are then created to override the default implementation as needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear, but do you understand the difference between subclassing and conforming to a protocol? Above you say "Subclasses are then created", but you don't subclass anything.
- Let's assume the configuration is stored in memory in a way that is convenient for the frontend to display, but not in the expected format needed to send to the backend. | ||
|
||
- Each watch series also has a different data structure we need to convert from. | ||
|
||
- We'll use the Template Method pattern to define the steps needed to convert the configuration to the expected format. | ||
|
||
- The pattern will allow us to cater to different watch series by providing a custom implementation for each series. | ||
|
||
## Domain application | ||
- Each series would have its own implementation of the steps needed to convert the configuration to the expected format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent
func process() { | ||
mapDataForWatchCaseSize() | ||
mapDataForWatchCaseMaterial() | ||
mapDataForWatchBand() | ||
mapDataForWatchBandSize() | ||
mapDataForWatchEngraving() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this process class calls all the same methods as the default implementation provided in your extension, why call it here again? This class can simply conform to the protocol and have an empty implementation and it will work just fine.
selectWatchBand() | ||
selectWatchBandSize() | ||
selectWatchEngraving() | ||
class Series10AppleWatchConfiguration: AppleWatchConfigurationTemplate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a class or can it be a struct?
func process() { | ||
mapDataForWatchCaseSize() | ||
mapDataForWatchCaseMaterial() | ||
mapDataForWatchBand() | ||
mapDataForWatchBandSize() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does your process method only call 4 of the 5 methods defined below?
selectWatchCaseMaterial() | ||
selectWatchBand() | ||
selectWatchBandSize() | ||
class HermèsSeries10AppleWatchConfiguration: AppleWatchConfigurationTemplate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a class?
func selectWatchCaseMaterial() { | ||
print("Configure default Apple Watch case material.") | ||
func mapDataForWatchCaseSize() { | ||
print("Implementation for converting the front data structure for the Apple Watch Series 10 case size.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is the default implementation, suggest editing all these methods in this extension to read: "Default implementation for..."
Also, what is "front data"? "frontend data" perhaps?
Also, do you mean: "for concerting INTO the frontend data structure..."?
- The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects. | ||
#### Abstract class: | ||
|
||
- Defines the steps in the sequence needed to map the configuration to the expected format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't define any sequence; you just define a set of methods to call. Remove the word sequence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scrap that. We discussed this. Your code is missing the critical part which preserves the sequence.
func process() { | ||
mapDataForWatchCaseSize() | ||
mapDataForWatchCaseMaterial() | ||
mapDataForWatchBand() | ||
mapDataForWatchBandSize() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By implementing your own process method you are loosing the templates ability to define the sequence. But we discussed this earlier.
No description provided.