Circular dependencies versus DRY

感情迁移 提交于 2019-12-04 06:25:51

Agree with Knives. Circular depedencies is a design smell. Refactor it Mercilessly!

This can be challenging in the case where business objects are tightly coupled. In most cases this can be solved through dependency injection.

Pseudo C++ Example:

class Employee {
    Company company;
};

class Company {
    vector<Employee> employees;
};

Tricky? Not neccesarily:

template<class CompanyT>
class Employee {
    CompanyT company;
};

class Company {
    vector<Employee<Company> > employees;
};

More primitive types, which must depend on a higher level, can be abstracted to work with any sort of other type, so long as it fulfills its contracts.

Sounds like you need a third assembly...

If your String library really needs your XML library, it is probably an indication that your String library needs to be refactored into a lower-level data type definition and "core utilities" (no external dependencies, if possible), and another higher-level library that may bring in XML, SQL, regular expressions, or whatever else you find useful at the application layer.

Make it an extension method that is defined in the xml assembly (based on your comment "conversion method that accepts XML and converts to a string based format"). It is dealing with xml. Just like Linq does for IEnumerable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!