[Note] Collaborator vs. the Factory

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.