You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thank u for contributions in computer science world.
While I was reading ur example, I asked myself about the domain models. I think that constructors have a lot of responsabilities, since they call set methods in which it validates and throw exceptions if it violates any domain rule. Why do u use constructors and not another pattern? Maybe a SFM (static factory method) or Builder can help to keep constructors simpler.
Thanks in advance.
The text was updated successfully, but these errors were encountered:
@jpoh97 Thanks for your feedback. It's always the constructor's responsibility to initialize the object's state. The use of internal setter methods doesn't complicate that, just delegates some details. This technique is know as self-delegation. A Builder generally works for an anemic object, with some visibility on setter methods. A Factory Method can indeed be used in front of a private constructor to make creation more fluent.
Hi Vaughn.
First of all, thank u for contributions in computer science world.
While I was reading ur example, I asked myself about the domain models. I think that constructors have a lot of responsabilities, since they call set methods in which it validates and throw exceptions if it violates any domain rule. Why do u use constructors and not another pattern? Maybe a SFM (static factory method) or Builder can help to keep constructors simpler.
Thanks in advance.
The text was updated successfully, but these errors were encountered: