A proper way for JPA entities instantiation « Paul Szulc's Blog - 0 views
-
A proper way for JPA entities instantiation
- ...31 more annotations...
-
And you shouldn’t really care, all that is important is that UserService depends on dao and webservice object.
-
calling new User(“someName”,”somePassowrd”, “someOtherName”, “someOtherPassword”) becomes hardly readable and maintainable
-
Instead of making the desired object directly, the client calls a constructor (or static factory) with all of the required parameters and gets a builder object. Then the client calls setter-like methods on the builder object to set each optional parameter of interest. Finally, the client calls a parameterless build method to generate the object, which is immutable. The builder is a static member class of the class it builds.