Example of robust, flexible, and extensible model composition using dependency injection via protocols and immutability #2630
Replies: 1 comment
-
|
The example above is simple to emphasize the root concepts. To prove this approach's viability in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In the discussion of #2625, the benefits of dependency injection and immutability after validated construction were both discussed in terms of making the composition of models less fragile, easier to maintain and extend, and safer to use. So, here is an example of that.
@ramaroesilva I encourage you to add a
Rectangleclass that implementsCylinderBaseand that is constructed fromlengthandwidthparameters. You should not have to touch theCylinderclass at all in order to use this new "component model" (!), because it meets theCylinderBaseprotocol. Bonus points for a refactor of the existingSquareclass to use the newRectangleclass. I'm happy to provide support and further discussion.Beta Was this translation helpful? Give feedback.
All reactions