This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Is it good design to have a constructor with parameters being not within the class of the constructor?
So you see I have two properties within my constructor only for internal calculation to represent the property newDate. Is that totally okay or should I do that in a method which returns a new Instance of User instead of a constructor?:
There's nothing wrong with using a constructor that way. However, a factory method has the advantage of being able to create subclasses of the return type, and it isn't even required to return an instance at all.
I generally use factory methods for my "value" classes, immutable classes that model some sort of value (examples from the API are Integer, String, etc), so I have the option to add value caching to my class later on, even if I usually don't. With most classes though, I usually just make a public constructor.
If you can foresee that you want to provide clients with subclasses of your User class later on, you should use factory methods. Otherwise I would just go with the constructor.
Wait what others have to say, they may have much more insight in this matter than I do.
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.