Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design Principle High Fan in vs High Fan out

Could anyone please explain this to me with an example? I am getting contradicted myself

  • High Fan in: A given class designed in such a way that it a high number of other classes can easily consume it.
  • High Fan out: A class should be using lot of other classes.

Both seems self contradictory. Can any one explain it with an example? possible in .NET framework.

like image 300
Hunter Avatar asked Nov 03 '10 22:11

Hunter


4 Answers

High Fan In is good rule for low level classes. They should be highly reusable by higher level classes. High Fan Out is good rule for high level classes. They should not "reinvent the wheel", but use the already existing code - found in low level classes.

So the rules are not contradicting because they relate to different classes.

like image 92
Dialecticus Avatar answered Oct 05 '22 10:10

Dialecticus


Really the truly problematic case is when you have both high fan-in and high fan-out:

  • Low fan-in, low fan-out: a module with little dependencies in either direction. All good.
  • High fan-in, low fan-out: a module that's highly depended upon, but itself doesn't depend on much. Like a low-level utility library.
  • Low fan-in, hight fan-out: a module that depends on lots of other modules, but a few if any modules depend on it. You really can't avoid having one top-level module to tie your whole application together, and naturally this module will depend on each and every other module in the system.
  • High fan-in, hight fan-out: a very problematic module that can break / need changes whenever one of its many dependencies changes, and it'll in turn break many other parts in the system that rely on it.
like image 36
Rene Saarsoo Avatar answered Oct 05 '22 09:10

Rene Saarsoo


Where did you read the High Fan Out principle? AFAIK, it is bad with High Fan Out.

http://it.toolbox.com/blogs/enterprise-solutions/design-principles-fanin-vs-fanout-16088

High fan-out in object-oriented design is indicated when an object must deal directly with a large number of other objects. This is indicative of a high degree of class interdependency. In general, the higher the fan-out of an object, the poorer is the overall system design.

Also mentioned in Code Complete, High Fan In with Low Fan Out are good class designs.

like image 36
Jeanno Avatar answered Oct 05 '22 10:10

Jeanno


Agree with @Jeanno. High Fan-Out is undesirable.

"The fanout of a module is the number of calls from that module. At least three studies have concluded that fanout squared is one component of a design metric that correlates well to probability of defect." Grady, R.B., "Successfully applying software metrics," in Computer , vol.27, no.9, pp.18-25, Sept. 1994 doi: 10.1109/2.312034

like image 32
Melvin Perez-Cedano Avatar answered Oct 05 '22 09:10

Melvin Perez-Cedano