Open
Conversation
0b1331f to
51d21ef
Compare
51d21ef to
241ea85
Compare
241ea85 to
4069df1
Compare
e1c2a19 to
e5f3274
Compare
e5f3274 to
a235f20
Compare
JavierCane
approved these changes
May 3, 2021
Member
JavierCane
left a comment
There was a problem hiding this comment.
Feel free to merge and commit the review suggestions afterwards in main if you prefer so 😊
| @@ -0,0 +1,126 @@ | |||
| # PHP Bootstrap (base / project skeleton) | |||
| @@ -0,0 +1,65 @@ | |||
| { | |||
| "name": "codelytv/php-bootstrap", | |||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace CodelyTv\StepShotgunSurgery\Application; |
Member
There was a problem hiding this comment.
It would be awesome to talk about the problem domain in the example title instead of revealing the illustrated code smell.
Why:
- Avoid giving hints on how to approach the solution
- Avoid collision with other examples for this very same code smell
- Avoid having to decide which code smell include in the example name in cases where multiple of them are illustrated
- Be able to be consisten about the example "branding' between languages. That is, not having to include the language in its folder name
Alternative suggestion: course_steps_duration_calculator
|
|
||
| public const QUIZ_QUESTION_DURATION = 5; | ||
|
|
||
| # Important: don't forget to add here the type!! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an example for illustrating Shotgun Surgery Code Smell, in which we compute the duration of different course
Steptypes.The logic for determining the duration of a
Stepis coupled to the step type:The
1.1and1.5are factors that might represent:In this example, instead of making the behaviour cohesive to the data, we have intentionally break the cohesion by spreading the behaviour in many classes and unnecessary abstractions.
Showing Shotgun Surgery Smell
In our current context, our platform only support a few types of
Steps, and we know that we will add new ones in the near future, so the lack of cohesion will be a change preventer.To show Shotgun Surgery smell, we can try to add a new
CodeExerciseSteptype with a new duration logic.For that, we can start adding a new test in
GetStepDurationTestthat validates the behaviour of the duration for the new type.Then, if we follow the same patterns for adding the production code, the implementation becomes crazy:
STEP_TYPE_CODE_EXERCISEconstant inStepEnumsclass.STEP_DURATION_MULTIPLIER_CODE_EXERCISEconstant inStepEnumsclass.StepDurationCalculatorCodeExerciseclass.StepDurationCalculatorFactory.DurationMultiplierclass.STEP_DURATION_MULTIPLIER_CODE_EXERCISEto theSTEP_TYPESarray inStepEnumsclass.Solving Shotgun Surgery Smell
If we take a look to the different abstractions, we will realize that all of them are coupled to the
Steptype. So we can perform some refactorings (Move method, Move constant, Inline class, Parallel change) for gaining cohesion and reduce accidental complexity.The main focus of the refactorings should be:
DurationMultiplierStepDurationCalculatorStepEnums