<title>Collaborator-vs-he-factory</title>Collaborator vs. the Factory
- Your code should either be in the business of doing business logic or in the business of instantiating and WI Ring other objects together
- What's this effectively means was that your either has classes with ifs and loops (your business logic) or are you having classes with new operators (your factories). Either process the logic or create the object
- But in practice you need one factory class each time your cross an object lifetime
- The removal of the new operators from our business logic classes, we need to ask for Our?collaborators?instea D of making them
- ? This means, each class has only knows of classes with which it's in direct contact and which it needs to get it Job done.
- ? The trick lies the view of the world from the factory are different than the view from the collaborator .
- The collaborators only know on its direct dependecies and the factories know about everything, and so is a good thing .?
But in my experience I saw there is times when objects is created based on business logic. So, the some object requires a certain object, with a certain interface. The tricky part is, the concrete object? Type is determined at runtime in some business logic code.
- ? The factory control the wiring process keeping the IFS out of it (as much as possible).
- A single factory can being responsible for a whole object graph, so there are not necessarily a one-to-one correspondence ther E between classes and factories
Original link: collaborator vs. the Factory
[Note] Collaborator vs. the Factory