-
Notifications
You must be signed in to change notification settings - Fork 134
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
Example for Shotgun Surgery #24
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
Step
types.The logic for determining the duration of a
Step
is coupled to the step type:The
1.1
and1.5
are 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
CodeExerciseStep
type with a new duration logic.For that, we can start adding a new test in
GetStepDurationTest
that 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_EXERCISE
constant inStepEnums
class.STEP_DURATION_MULTIPLIER_CODE_EXERCISE
constant inStepEnums
class.StepDurationCalculatorCodeExercise
class.StepDurationCalculatorFactory
.DurationMultiplier
class.STEP_DURATION_MULTIPLIER_CODE_EXERCISE
to theSTEP_TYPES
array inStepEnums
class.Solving Shotgun Surgery Smell
If we take a look to the different abstractions, we will realize that all of them are coupled to the
Step
type. 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:
DurationMultiplier
StepDurationCalculator
StepEnums