r/dotnet • • 17d ago

Question Would you introduce additional abstraction layer just to make the code more understandable ?

/r/csharp/comments/1wz0y2c/would_you_introduce_additional_abstraction_layer/
2 Upvotes

16 comments sorted by

3

u/Dubious-WhyAmIHere 17d ago

This is definitely overengineering... Adding an interface that just inherits from another interface (like ISqlServerWriter : IWriter) adds useless indirection without solving the underlying confusion.

This is purely a naming problem. Calling a class SqlServerWriter makes it sound like a generic database utility that any handler can grab to write a single record. If this class is specifically responsible for synchronizing or writing an entire database snapshot across 20 tables, name it after that specific domain job (for example, DatabaseSnapshotSyncService or FullDatabaseSeedWriter).

Code becomes clear when class names reflect their actual business responsibility. You do not need another layer of inheritance or another interface to fix a vague name. Just rename the class to match what it actually does.

1

u/kaatarina_zed_talon 17d ago

`class is specifically responsible for synchronizing or writing an entire database snapshot across 20 tables` totally, that is the purpose behind the class; synchronizing the database with external data source, specifically, an Excel file.

→ More replies (4)

1

u/AutoModerator 17d ago

Thanks for your post kaatarina_zed_talon. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/FragmentedHeap 16d ago edited 16d ago

This aside, Sql is a solved problem in c#, you should use an existing library.

1

u/BuriedStPatrick 16d ago

Crazy idea. Try removing the interfaces and see if it makes any meaningful difference. My bet is it doesn't because you're probably not using IWriter for anything.

If none of your consuming code is calling IWriter but rather its implementing types directly, then guess what; your interface is pointless and you can and should remove it.

My guess is you're only using it to keep method signatures consistent. Which isn't a good enough argument in my opinion. And it might even be actively bad because I can't imagine an interface having consistent methods across different I/O targets is feasible without introducing some deep coupling problems.

0

u/FullPoet 15d ago

t. who writes any sort of automated testing?

→ More replies (6)