Controlling Constructor Access in a Class Schema for Domain Events
Hi everyone!
What is the correct approach if I want to define a class schema, but need to control or disable the constructor?
My use case is a DomainEvent class. It has a payload, an id and an occuredAt date. I want them to be in the schema, but the caller should not able to set id and occuredAt date.
I was thinking about a static create function that only takes the payload as argunent and to disable the constructor, But marking the constructor as protected gives me a linter warning from the Effect language service. So I wonder if doing this will break soomething sooner or later. Obviously it is seen as an antipattern.
I think this use case is not too uncommon: So I‘m curious how others do this.
What is the correct approach if I want to define a class schema, but need to control or disable the constructor?
My use case is a DomainEvent class. It has a payload, an id and an occuredAt date. I want them to be in the schema, but the caller should not able to set id and occuredAt date.
I was thinking about a static create function that only takes the payload as argunent and to disable the constructor, But marking the constructor as protected gives me a linter warning from the Effect language service. So I wonder if doing this will break soomething sooner or later. Obviously it is seen as an antipattern.
I think this use case is not too uncommon: So I‘m curious how others do this.
