simon fletcher wrote:I think sometimes they are called factory methods.
Paul Clapham wrote:Well, no, not every method which happens to return an object is a factory method. Consider for example an ordinary getter method (public Date getDate()) which gets a Date attribute from some object. You wouldn't call that a factory method, would you?
I think you would only call it a factory method if you knew that the method was actually creating the object it was going to return. Of course that's just a brief and incomplete description -- have a look at the Wikipedia article Factory method pattern for much, much, much more information about the pattern.
Paul Clapham wrote:I had a quick look through the Java API and came up with BigDecimal.valueOf(long), which returns a BigDecimal object. I don't think that's a factory method, at least not according to the Wikipedia article which I linked to.
Campbell Ritchie wrote:I cannot imagine writing a factory method and not making it static. For more discussion look here amd here, and find the book mentioned.
Campbell Ritchie wrote:I cannot imagine writing a factory method and not making it static.