java - Is inter-class dependency an anti-pattern -


Best explained my small snippet - here we have two classes here Math and SolveEquation . They both rely on one another, is this traditional practice? Or is there an anti-pattern that should be avoided from all expenses?

Note: Please avoid alternative solutions. This example was made to answer the suspicions made by me. Thank you.

Example:

Request for class solution {public static insulequuction (int x, int y) {return Math.add (x, y) + Math.sub (X , Y); }} Class mathematics {public static int activation (Intex X, int y) {return SolveEquation.solveEquation (x, y); } Adding public static (int x, int y) {return x + y; } Public fixed int sub (int x, int y) {return x - y; }}

This condition is called a circular dependency, and yes, should avoid. At least if you know that you can avoid them, then do so.

Edit: There are several reasons why you should not stay with them.

The first is that some languages ​​(if I remember that have already happened to me in C #), then you will not be able to create modules with circular dependencies. (Whoops)

The second one is that it tells me that the quality of the code can be improved. Because it usually shows the symptoms of tight coupling, which makes your code less usable. In addition, in your example, this is not the case (because you have used static methods), but when you want to make them objects, it will be difficult. Especially if you are using dependency injection.

More reasons are listed

Circular dependency software can create many unwanted effects in programs. The most problematic approach from a software design point is the tight coupling of mutually dependent modules, which reduces the use of a module or makes it impossible.

Circular Dependency A small transformation of local changes in other modules in other modules and consequent uncertain global impact (program errors, compilation errors), as a result of circular dependence can result in infinite recaptans or other unexpected failures.

Circular dependence can be prevented by some indirect automated garbage collectors (which use reference count) to remove the unused object.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -