Solutions Flashcards
Replace Conditional with Polymorphism.
When using type information to branch logic.
Replace Conditional with Null Object.
For removing excessive nil checks.
Extract Method.
For making a method smaller, reusable, less complex, and decreasing duplication.
Rename Method.
For improving readability.
Extract Class.
For making classes simpler, more reusable and with a better SRP.
Extract Value Object.
For reducing duplication, making the code simpler and the business logic - more cohesive.
Extract Decorator.
For adding additional behaviour to an object dynamically - it makes SRP better.
Extract Partial.
For removing complex or duplicated view code from your application.
Extract Validator.
For making validations reusable.
Introduce Parameter Object.
To reduce the number of input parameters to a method.
Introduce Form Object.
To remove business logic from controllers when processing data.
Introduce Explaining Variable.
Improves readability.
Replace callback with a method.
When callbacks contain business logic it helps increase reusability.
Replace mixin with composition
Provides safe steps for cleanly removing mixins that have become troublesome.
Replace subclasses with strategies
Replace the subclasses with individual strategy classes. Each strategy class will implement a common interface.