How to generally decide between FACTORY and constructor?

Thiago Colares <[email protected]>
Newsgroups gmane.comp.programming.domain-driven-design
Message-ID <CANgyUW7B+yntzXe5exfXqgVFaCQziz_a0X4fvLUpb_0PCO_z1g@mail.gmail.com>
Hi,

AFAIK, a FACTORY is a good choice when a constructor "becomes complicated
or reveals too much of the internal structure". So, a FACTORY can be used
to encapsulate it.

*But how do I know a constructor became too complex? What's the mininum
warning sign?*

So far, I take for granted that: If a constructor implements anything else
then setting values, it's a factory-elegible.

Also, when I do that, it helps me a lot on unit testing. Thus I avoid
mocking unecessary objects, for example. The same way if I need to test a
private method, so it shouldn't be private, maybe there is something
between the lines here.

Cheers,

--
Thiago Colares
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.