« Return to Thread: Draft SIP: From constructors to factories: Uniform treatment of object creation

Re: Draft SIP: From constructors to factories: Uniform treatment of object creation

by Ben Hutchison-2 :: Rate this Message:

Reply to Author | View in Thread

David MacIver wrote:
> Summary: Make it easy to switch from constructors to factories after
> the fact by adding a mechanism where "new Foo(stuff)" can translate to
> an invocation of a user defined method on the companion object.
>
> http://www.drmaciver.com/factories-sip.xhtml
>  
Generally, I like the idea of being able to switch from new Foo() to
Foo.new().

I have a question about your SIP. It seems that you propose that, when
the compiler encounters new Foo(x, y), if and only if c'tor signature
Foo(x, y) is not defined does it look for factory method Foo.new(x, y).

Presumably you considered the alterative that it looks for Foo.new(x, y)
first, then if not found, new Foo(x, y)? This would allow overriding
c'tors with a factory without removing the affected c'tor. Why do you
prefer the former option?

-Ben

--

       

*Ben Hutchison
Senior Developer
* Level 2 476 St Kilda Road Melbourne VIC 3004
T 613 8807 5252 | F 613 8807 5203 | M 0423 879 534 |
www.ibsglobalweb.com <http://www.ibsglobalweb.com/>


 « Return to Thread: Draft SIP: From constructors to factories: Uniform treatment of object creation