开发者

dotNet should a class library only expose an interface or an implementation too

开发者 https://www.devze.com 2023-02-20 01:02 出处:网络
I\'m teaching myself as I go and am the only developer at our organisation. I\'ve started splitting particular tasks off into class libraries so that as organisation needs grow I can re-use that code.

I'm teaching myself as I go and am the only developer at our organisation. I've started splitting particular tasks off into class libraries so that as organisation needs grow I can re-use that code.

I tend to have for e.g. IMailingThingie and MailingThingie in the class library since when I add a reference to the library bot开发者_Go百科h resolve.

I also feel like this reduces duplication of code but has led to some hoop jumping (for example to accommodate daily MailingThingie rules and Monthly MailingThingie rules)

Is it better practice to expose only the interface in the class library and code the implementations on a project by project basis?

I'm using C# dotNet but I guess the architectural decision at this level is language neutral...

SolutionRoot1
--ClassLibrary
----IMailing
----Mailing
--Project1
----Reference
--Project2
----Reference

or

SolutionRoot1
--ClassLibrary
----IMailing
--Project1
----Reference
----Mailing
--Project2
----Reference
----Mailing


It's better to share implementation if that leads to code re-use. If you're jumping through hoops because of differing business rules, you should look at inheritance to allow you to share the basics and allow each project to define the specifics.

The best practise is to understand the difference between sharing an interface and sharing an implementation so you can choose the best solution given the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号