Circular dependency

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
Line 3: Line 3:
 
Some IDEs like Visual Studio actively disallow such dependencies between packages but others allow it.
 
Some IDEs like Visual Studio actively disallow such dependencies between packages but others allow it.
  
==Example==
+
>==Example==
 
Imagine that we have divided our system into a model and a gui package. The model package contains the domain classes while the gui package contains the GUI classes.  
 
Imagine that we have divided our system into a model and a gui package. The model package contains the domain classes while the gui package contains the GUI classes.  
  
 
In a bad design, we could have a circular dependency between these packages. The gui package may need knowledge of the domain classes in the model package in order to be able to display information appropriately. The model package may tell the gui package to update the display when changes occur. This is obviously a bad design for several reasons and the model package should never really know about the GUI. It is also an example of the Circular Dependency anti pattern.
 
In a bad design, we could have a circular dependency between these packages. The gui package may need knowledge of the domain classes in the model package in order to be able to display information appropriately. The model package may tell the gui package to update the display when changes occur. This is obviously a bad design for several reasons and the model package should never really know about the GUI. It is also an example of the Circular Dependency anti pattern.
 +
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://ohupomeqawu.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
 +
----
 +
=[http://ohupomeqawu.co.cc CLICK HERE]=
 +
----
 +
</div>
  
 
==Liabilities==
 
==Liabilities==

Revision as of 06:34, 18 November 2010

The Circular Dependency anti pattern occurs when two modules depend directly or indirectly on each other to work. It is usually considered acceptable to have some circular dependencies between domain classes and objects. In the real world, circular dependencies are very common. However, if there are circular dependencies between modules such as packages, that is considered an anti pattern. This is closely related to the Acyclic dependencies principle.

Some IDEs like Visual Studio actively disallow such dependencies between packages but others allow it.

>==Example== Imagine that we have divided our system into a model and a gui package. The model package contains the domain classes while the gui package contains the GUI classes.

In a bad design, we could have a circular dependency between these packages. The gui package may need knowledge of the domain classes in the model package in order to be able to display information appropriately. The model package may tell the gui package to update the display when changes occur. This is obviously a bad design for several reasons and the model package should never really know about the GUI. It is also an example of the Circular Dependency anti pattern.


Liabilities

  • Tight coupling between two modules in a circular dependency makes it more difficult to reuse one of them in another context.
  • Maintainability is decreased as changes in one module may propagate to the other module and back in a kind of domino effect.
  • Other side effects like memory leaks are possible because circular dependencies can impact automatic garbage collection.

Related design heuristics


Personal tools