Could anyone please explain this to me with an example? I am getting contradicted myself
Both seem mutually contradictory. Can anyone explain it with an example using .NET framework if possible?
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.
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.
Really the truly problematic case is when you have both high fan-in and high fan-out:
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, RB, "Successfully applying software metrics," in Computer , vol.27, no.9, pp.18-25, Sept. 1994 doi: 10.1109/2.312034
From the book Code Complete, by Steve McConnell, you want High fan-in and Low-to-medium fan-out:
High fan-in refers to having a high number of classes that use a given class. High fan-in implies that a system has been designed to make good use of utility classes at the lower levels in the system
So, high fan-in is good because the class is used a lot. The more classes that can make use of a class, the better class it is.
Low-to-medium fan-out means having a given class use a low-to-medium number of other classes. High fan-out (more than about seven) indicates that a class uses a large number of other classes and may therefore be overly complex.
Fan-out, on the other hand, is how many things the class calls. I don't think high fan-out is ever really desirable. Yes, you want your high-level classes to use lower-level utility classes that are themselves high fan-in, but if you call a lot of them from one class you probably could break the calling class into smaller, less complex parts. That way each part becomes low-to-medium fan out by only calling the few utility classes they need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.