Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing code in C# projects [closed]

I have an interface:

public interface IMyObject
{
}

I have an abstract class:

public abstract class MyObject : IMyObject
{
}

And I have a class:

public class MyExtendedObject : MyObject
{
}

There are many interfaces, abstracts and concretes like this in my project. I wonder what is the best scenario to organize the code in namespace (folders in project) point of view. Should I put all related stuff under the same folder or should create, for example a Base namespace for abstract classes, Interfaces namespace for interfaces and another namespace for extended objects?

like image 381
mnyarar Avatar asked Jan 12 '23 05:01

mnyarar


2 Answers

The best way is subjective and poject dependent.

Like a suggession I would say:

move in separate folder interfaces and abstract classes, so separate them from concrete implementation classes.

+ Absrtacts 
     -> IMyObject.cs 
     -> MyObject.cs 

+ Concrete 
     -> MyExtendedObject.cs
like image 177
Tigran Avatar answered Jan 13 '23 20:01

Tigran


Robert C. Martin (one of the founding fathers of Agile and now the Software Craftmanship movement) has a whole talk on that that is really worth watching

It's based on Ivar Jacobson's Object Oriented Software Engineering: A Use Case Driven Approach.

To summarize it in a few sentences, your project structure should reflect what it models and not the technology or particular language constructs you use. In the case of your abstract/interface/concrete classes this means that using a structure where you put all your abstract classes in a folder/namspace/assembly, your concrete classes in another folder/namespace/assembly is not the way to go (even though it is very common to find projects where this approach is taken).

like image 22
Rui Avatar answered Jan 13 '23 18:01

Rui