C#C
C#2y ago
Roach

How do I reduce class coupling? Is class decoupling always necessary?

Hello, yesterday I discovered the code metrics feature in vs. The Microsoft doc says "9" would be the "magic number" regarding class coupling.
When I looked at my metrics results, I discovered I got a class with 43 class coupling score, where a single method holds 27 of the score and some more classes with 20+ class coupling score. I mean everything works fine at the moment, so theres no issue needed to be fixed that stops my code from working but since ms docs seem to say good metric scores indicate better manageable and less subsceptible code, I thought it couldn't harm to ask.

When I googled I got results mentioning implementing interfaces but dont even know if I got pointed to the right direction by that.
As far as I understood, one could make an Interface ICar whichs content would be like a template classes that use ICar would have to implement as well which means one could make different types of car-classes with i.E different behaving Drive methods if I understood correctly.

So if I understood those google/ms doc examples correctly til here, I still don't know how I would apply Interfaces onto my classes that I'm don't really even able to compare to that examples I read.

The class with a 43 score is a class that handles an import process for csv files into a sqlite database. The method with 27 score is ProcessCsvFileAsync.

https://github.com/MisterRoach/WoW_AH_Data_Project/blob/master/WoW_AH_Data_Project/Database/DatabaseImportCsvs.cs
Was this page helpful?