Coder Social home page Coder Social logo

Comments (3)

michael-rubel avatar michael-rubel commented on July 28, 2024

The objects are immutable, but not in the constructor.

If you try to assign the value manually, it will throw an exception:

$test = new Text('value1');

$test->value = 'new value'; // ... Exception

I've considered making constructors final, but this way developers are limited in extending/overriding the constructor logic, e.g. Name extends Text and adds sanitization logic. With construct being final we'll be unable to do that.

from laravel-value-objects.

michael-rubel avatar michael-rubel commented on July 28, 2024

Came up with a non-breaking solution, and also to keep extendability in #14

This will be shipped as a minor release in a while.

from laravel-value-objects.

MuntzMathias avatar MuntzMathias commented on July 28, 2024

I would have simply put the constructor in protected so that the developers cannot use it without passing a static method which will act as a factory.

protected function __construct(string|Stringable $value)
{
    // ....
}

public static function make(mixed ...$values): static
{
    return new static(...$values);
}

from laravel-value-objects.

Related Issues (3)

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.