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?

  • 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 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". – Doc Brown May 23 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 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 at 20:15
  • Related / maybe already answering this question: Is there a valid case for two components to depend on each other? – Doc Brown May 23 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.