Constructor versus shared method

olsonpm

Well-known member
Joined
Aug 24, 2010
Messages
46
Programming Experience
Beginner
What is the purpose of using shared methods that return an instance of a class, as opposed to a constructor?

ie: in VB.net, the system.drawing.color class has shared method "FromArgb(int, int, int) as color". This is different from java's implementation which simply is a constructor that takes three ints. Why the decision to do one or the other?

thanks,
Phil
 
Ah, I did a bit more googling (it took me a while to find the right keywords). Here are my results

static method or instance constructor - Stack Overflow

From that one reading, the matter seems subjective and could go either way. I prefer constructors mainly because I'm used to it being a java person. The link says that constructors seem to be more intuitive (a study was done showing this). However, there are definitely good points for having a factory method (shared method returning an object). One being that you can describe what is going on, as opposed to just having an ambiguous 'new' signature.

Hopefully someone finds this post helpful, as it took me a while to find what i was looking for.
 
Back
Top