1

Is it doable, desirable to organize project classes, dependencies in Tree/DAG structure?

To be more specific. In applications (not libraries) we have always some entry point, am I right? Some main class. Here we keep some core dependencies, which have other dependencies and so on. We treat it as root of dependency tree.

I wonder if we should keep our dependencies in hierarchical order with some abstraction levels? How to organize complex class connections, keep low coupling, prevent from spaghetti code?

xana
  • 117
  • 3
  • 1
    These are two questions. Technically, it is doable, that is trivial (just whenever one finds a cyclic dependency, it can be decoupled by introducing some interfaces). If it is *desirable* is a completely different question: the question is equivalent to the question if there should be cyclic dependencies, and that one was already asked and ansered on this site before ... – Doc Brown May 23 '20 at 18:35
  • 1
    .. and on the level of packages (instead of classes), the canonical answer is ["no, it is not desirable, but there are exceptions"](https://softwareengineering.stackexchange.com/questions/317234/why-support-cyclic-dependencies-at-all-are-there-valid-use-cases). – Doc Brown May 23 '20 at 18:43
  • 2
    @DocBrown The supposed duplicate is completely different from the question here. At a base level, this question focuses on an hierarchy of classes whereas the duplicate focuses on peers. This question does not entail cyclical dependencies, which is what the duplicate question and its answers focus on. – Flater May 23 '20 at 19:14
  • @DocBrown I agree with Flater: although there is some relation between both question, they are not the same: "*is there a valid case for two components to depend on each other*" adresses a specific case and asks if it can make sense. Here it is presenting the dependencies as a DAG. So it's not about making sense but feasibility despite mutual dependencies are possible (e.g. spanning tree?) . – Christophe May 23 '20 at 20:15
  • Related / maybe already answering this question: [Is there a valid case for two components to depend on each other?](https://softwareengineering.stackexchange.com/questions/233837/is-there-a-valid-case-for-two-components-to-depend-on-each-other) – Doc Brown May 23 '20 at 21:18

0 Answers0