Strategic 1.2.0 (Painless Strategy Pattern in Ruby and Rails) shipped with a minor new feature: having a default strategy on Strategic classes of 'default', which is activated if a ModelNamespace::DefaultStrategy class is present (otherwise, no default strategy is set).
This is in addition to the previous support of being able to declare an explicit `default_strategy` name (e.g. `default_strategy 'quebec'` for TaxCalculator expects `TaxCalculator::QuebecStrategy` to exist)
Also, Strategic 1.2.0 has been tested and confirmed to be working with Rails 7.
In any case, below is a reminder from the README of what the Strategic library is all about:
"if/case conditionals can get really hairy in highly sophisticated business domains. Object-oriented inheritance helps remedy the problem, but dumping all logic variations in domain model subclasses can cause a maintenance nightmare. Thankfully, the Strategy Pattern as per the Gang of Four book solves the problem by externalizing logic via composition to separate classes outside the domain models.
Still, there are a number of challenges with "repeated implementation" of the Strategy Pattern:
- Making domain models aware of newly added strategies without touching their code (Open/Closed Principle).
- Fetching the right strategy without the use of conditionals.
- Avoiding duplication of strategy dispatch code for multiple domain models
- Have strategies mirror an existing domain model inheritance hierarchy
- Strategy Pattern support through a Ruby mixin and strategy path/name convention
- Automatic discovery of strategies based on path/name convention
- Ability to fetch needed strategy without use of conditionals
- Ability to fetch a strategy by name or by object type to mirror
- Plain Ruby and Ruby on Rails support
Strategic enables you to make any existing domain model "strategic", externalizing all logic concerning algorithmic variations into separate strategy classes that are easy to find, maintain and extend while honoring the Open/Closed Principle and avoiding conditionals."
No comments:
Post a Comment