开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜