Comments (4)
I'd guess it's to simplify code in other areas. Otherwise every time you load an item from your persistence layer you'd have to perform error checking but I've actually gone down the route of returning Result objects from the Mapper functions.
from white-label.
@roylee0704
Domain should always be in the persistence state. If we allow the software to continue working after an error in domain model, it may come into an invalid state, and save that state to the database.
Domain classes must throw an Exeption, for fail fast principle(FailFast @ MartinFowler).
Result monad is well suited for validating data before it is passed to domain class methods.
If an invalid state is passed to Mapper, and if this is the expected case, for example, when we added a new required field to the database, but only users can fill it out, we need to create an additional field, for example, CustomerOld, and wait for the moment when we can delete it without causing exceptions.
from white-label.
@NikitaIT I have to disagree with you.
I think you are misinterpreting fail fast principle as "must throw an Exception", even in the document you have attached, Matrin Fowler's main complaint is returning partially correct or default values that allow the system to continue operating in an invalid state.
I believe that the Result class handles the principle in the same was as an exception without destroying the fluidity of the system. You are not able to act on a failed Result object in the same way as the object type and your code is forced to handle it unlike exceptions which are frequently overlooked, undocumented and badly handled.
Either way, the current implementation within the project of returning a null value on the bad mapping neither fails nor is it visible.
from white-label.
@apparatusdeus
Let me explain, when we throw an exception we say "the code that we wrote does not seem to work correctly", when we return Result we say "the code works correctly, but we expect the operation to be processed with an error."
When we write code in entities, we say "this method should only be called with arguments appropriate to the contract, if this is not so, then I wrote the code incorrectly." Using Result, we actually delegate the decision on whether we are using the method correctly or not, this gives us the opportunity to ignore the error. Virtually all domain model methods become tryDoSomething.
This is similar to "First think, then speak" for code. This makes it possible to validate only IO, and as soon as the data crosses the boundary, we can trust the code, instead of trying.
- Result assumes a possible recovery reaction at the place of the method call.
- Fail Fast does not expect to restore the current task within the current context.
from white-label.
Related Issues (16)
- Sequelize with TypeScript
- Implementing Jwt Token jsonwebtoken as AuthProvider
- No activity HOT 1
- Race condition
- AggregateRoot constructor HOT 2
- What is the difference between id & userId? HOT 1
- why it is not strict ? HOT 8
- Using the same controller for multiple requests
- Why underscore private `_domainEvents` in AggregateRoot? HOT 3
- is this code base build properly HOT 1
- Use default parameters instead of thernary operator HOT 1
- [Golang] Implement one Bounded Context using Golang HOT 2
- Remove secret keys from repo. HOT 1
- How to apply common access control rules to many routes
- Attempting to access Result value in possible error case. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from white-label.