How to define an interface for use in multiple class files

  • Thread starter Hans De Schrijver
  • Start date
H

Hans De Schrijver

I'm new to C# development, so here's a basic question.

I'm developing a code library (no UI) where several of the classes will
implement an IPersistable interface.
Each class lives in its own class file (within the same project) but all
classes are defined within the same namespace DaySpanLib.
Now here's my question: given that the interface I need to develop will be
implemented by several classes, each of which live in their own .cs file, in
which file do I create the interface? Do I create a separate General.cs file
that contains general stuff like this interface?
So far I created a "public interface IPersistable" in a separate General.cs
file (also in the namespace DaySpanLib), and it compiles fine.
However, I'm wondering what best practices are with respect to things like
general interfaces and enumerations... where do you put them?

Any input is greatly appreciated.

-- Hans De Schrijver
 
J

John Saunders

Hans De Schrijver said:
I'm new to C# development, so here's a basic question.

I'm developing a code library (no UI) where several of the classes will
implement an IPersistable interface.
Each class lives in its own class file (within the same project) but all
classes are defined within the same namespace DaySpanLib.
Now here's my question: given that the interface I need to develop will be
implemented by several classes, each of which live in their own .cs file, in
which file do I create the interface? Do I create a separate General.cs file
that contains general stuff like this interface?
So far I created a "public interface IPersistable" in a separate General.cs
file (also in the namespace DaySpanLib), and it compiles fine.
However, I'm wondering what best practices are with respect to things like
general interfaces and enumerations... where do you put them?

You could even put the interface in its own file: IPersistable.cs.

But you might get tired of little tiny files for things like interfaces and
enumerations. In which case, you could put all such things into a single
Types.cs file. But that file might get too large, so you might start using
multiple files, separating the types by some criterion.

In other words, it doesn't matter. Do whatever seems most appropriate at the
time and simply realize that "appropriate" may change as the application
matures.

One other suggestion, though: is the concept of being Persistable unique to
the DaySpanLib? If not, then you might want to create a separate solution
for common types and define IPersistable there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top