Lately I’ve been advocating decoupling business logic from the framework (i.e. Magento) a lot.
This has multiple advantages:
- Benefit from test driven development (TDD) without having to mock a bunch of core classes.
- Possible reuse in different applications (for example Magento 1 and Magento 2)
- Having separated bounded contexts helps to view parts of the domain isolated and without distraction.
Even in chirurgic modifications that we often have to do in Magento projects, it is worth identifying the actual logic and extracting it from the actual Magento classes.
Let me demonstrate it with a real-world example: