how Yadic handles classes with multiple constructors

5 views
Skip to first unread message

Nick Barrett

unread,
Sep 22, 2013, 9:59:24 AM9/22/13
to ya...@googlegroups.com
Hi folks, I had a somewhat unexpected yadic situation the other day. I fixed it actually by a quick redesign (see footnote) - but interested in your thoughts.

I have a class with two static factory constructors of different types. In my container along with the class I want to instantiate, I have only one of the constructor types.

Yadic threw the unsatisfied constructor args exception.

I would have thought that in the constructor matching process, yadic would have found that one of the valid matches existed and would have used it. Perhaps yadic was being subtly opinionated about my design (dammit, it was right!!)

(Footnotey bit)
Anyway, I deleted the second constructor as it was a bit of a hack anyway for unit testing. I just needed to inject a more complete set of mock dependencies in the unit test and everything became lovely again.

Cheers
Nick

Daniel Worthington-Bodart

unread,
Sep 22, 2013, 10:10:41 AM9/22/13
to ya...@googlegroups.com

The current rule is: if it has public constructors use them (largest first) else use static (largest first). Currently it won't drop through from public to static but have wondered about relaxing that rule

--
You received this message because you are subscribed to the Google Groups "yadic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yadic+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Nick Barrett

unread,
Sep 24, 2013, 3:54:15 PM9/24/13
to ya...@googlegroups.com
Personally, I'm a BIG fan of static constructors because a) they look nice b) they are more descriptive than public constructors c) auto-completing your code in a decent IDE is even more of a joy and d) Joshua Bloch would love me for it.

So I would say, yes to that relaxation. But then again, if you are using yadic exclusively in your prod code to construct your objects then who gives a stuff about the static constructors?

On the 'size' debate, how do different constructors each with 1 arg but of different types stack up against each other in the precedence competition? 

I'm just arguing with myself for the sake of it really as I've long refactored that other constructor out of my code anyway, so perhaps I'll get my coat......
Reply all
Reply to author
Forward
0 new messages