How to organize Interfaces/classes/implementations in the project
I found some questions about how to organise projects (namespace, one class per file etc), but on a more specific note, how do you organize "things" that are very tightl开发者_StackOverflow社区y related ?
I usually end up with :
- an interface
IMyStuff
- a base (sometimes abstract) class that provides basic skeletton for that interface :
BaseMyStuff
- implementation classes
MyStuffWithBellsAndWhistles
,MyStuffWithChocolateFlavours
It seems to make sense that they should be in the same namespace, but it feels like my folders start to be a bit over-crowded if I put all these files together in the same folder (not actually a real problem, but it feels strange).
Would it be OK to define both the interface and the base class in the same file ?
Or would it be OK to group those things in sub-folders, but in the same namespace ? like this :
-MyNamespace
|-Interfaces
| -IMyStuff
| -IMyOtherStuff
|-BaseClasses
| -BaseMyStuff
| -BaseMyOtherStuff
|-Implementation
| -MyStuffWithAwesomeBehaviour
| -MyStuffWithGreatUsefulness
| -MyOtherStuffSoNeatYouWillCry
What are the "best practices" regarding this kind of organization ?
If the purpose of the interfaces is to abstract the implementation and allow for alternative implementations that are not known to the author of the interface, then I would recommend keeping them in an seperate project file. When constructing unit test projects or other consumers of the interface this will allow them to create a project reference that drags in only the interfaces and not the implementations. This means alternative implementations of concrete classes never need to have a reference to the original concreate representation.
精彩评论