Readonly class for immutable data objects #860
Unanswered
matthew-hallsworth
asked this question in
Q&A
Replies: 1 comment
-
Since the Data class is basically just some traits and interfaces, it shouldn't be too hard to create a readonly version. Notice: you will only be able to use constructor promoted properties, other properties are set by data outside of the constructor which isn't valid according to the readonly spec. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I use this class a lot in our application to build immutable data objects that I can pass around and be sure that the object has not changed from instantiation. However, we can now define a class as a readonly class instead of putting readonly against every attribute of the class.
When I try to readonly a class that extends the
Spatie\LaravelData\Data
class, I get the following problem in my IDE:'readonly' class cannot extend non-readonly class 'Data'
I'm wondering if there is a way to allow for immutable data objects in future revisions of the project? Or if there is a way to do this already, unfortunately after scouring the docs I just couldn't find it or it's in a place that's hard to find.
Thanks!
Matt
Beta Was this translation helpful? Give feedback.
All reactions