zoukankan      html  css  js  c++  java
  • Collaborator-vs-he-Factory

    Collaborator-vs-he-Factory

    Collaborator vs. the Factory

    • your code should either be in the business of doing business logic or in the business of instantiating and wiring other objects together
    • What this effectively means is that your either have classes with ifs and loops (your business logic) or you have classes with new operators (your factories).要么处理逻辑,要么创建对象
    • But in practice you only need one factory class each time you cross an object lifetime
    • To allow the removal of the new operators from our business logic classes, we need to ask for our collaborators instead of making them
    •  This means that each class only knows about other classes with which it is in direct contact and which it needs to get its job done.
    •  The trick lies that the view of the world from the factory is different than the view from the collaborator.
    • The collaborators only know about its direct dependecies and the factories know about everything, and that is a good thing. 

    But in my experience I saw there are times when objects are created based on business logic. So, some object requires a certain object, with a certain interface. The tricky part is that the concrete object  type is determined at runtime in some business logic code.

    •  Let the factory control the wiring process keeping the ifs out of it (as much as possible).
    • A single factory can be responsible for a whole object graph, so there is not necessarily a one-to-one correspondence there between classes and factories

    原文链接:Collaborator vs. the Factory

  • 相关阅读:
    Matlab画图-非常具体,非常全面
    PostgreSQL代码分析,查询优化部分,pull_ands()和pull_ors()
    Windows内核
    [WebGL入门]十,矩阵计算和外部库
    HOG特征-理解篇
    hdu 5035 概率论
    Hibernate对象持久化框架
    Thinkpad X200 屏幕备案
    64地点 Windows 8/7 根据系统 32地点PLSQL 耦合 64 地点 Oracle 11g
    阐述php(四) 流量控制
  • 原文地址:https://www.cnblogs.com/xilifeng/p/4703541.html
Copyright © 2011-2022 走看看