Git Product home page Git Product logo

Comments (4)

apparatusdeus avatar apparatusdeus commented on May 20, 2024

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.

NikitaIT avatar NikitaIT commented on May 20, 2024

@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.

apparatusdeus avatar apparatusdeus commented on May 20, 2024

@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.

NikitaIT avatar NikitaIT commented on May 20, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.