- Notifications
You must be signed in to change notification settings - Fork 142
Example for Shotgun Surgery #24
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
base: main
Are you sure you want to change the base?
Conversation
0b1331f to 51d21ef Compare 51d21ef to 241ea85 Compare 241ea85 to 4069df1 Compare e1c2a19 to e5f3274 Compare e5f3274 to a235f20 Compare 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.
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) | |||
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.
👀 😬
| @@ -0,0 +1,65 @@ | |||
| { | |||
| "name": "codelytv/php-bootstrap", | |||
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.
👀 😬
| | ||
| declare(strict_types=1); | ||
| | ||
| namespace CodelyTv\StepShotgunSurgery\Application; |
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.
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!! |
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.
🎩
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