3 ms·
Isn't it easier to create a static constructor? A public static method that validates everything, then calls the private constructor with the proper values? Us
by TrianguloY 3y ago
Isn't it easier to create a static constructor? A public static method that validates everything, then calls the private constructor with the proper values?
Using a static private method that is "hacked" as a call to the super constructor in the public one seems...strange.
- tadfisher 3y agoIt's better to not confuse data with behavior. Move the polymorphism to the data type, and model the behavior with an interface. Now you don't have to validate arguments to super() because there isn't one.
- iraqmtpizza 3y agoYou can't have default methods for equals, hashCode, and toString in Java interfaces. And even if you could, without access to the data they wouldn't be of much use.
- keeganpoppen 3y agoi find static constructors somehwat hideous in the sense that ultimately inevitably ends up running through the constructor regardless