2

I was assigned on a project (C# based) to work on, and i found there is a class and interface with same name in the same namespace [class : Payment, Interface : Payment]. so when i build the solution it gives me error that it is not allowed.

Renaming one of them will affect other many areas in the solution. Actually I don't know how was it working!!

Any ideas?

Thanks,

Omar.M
  • 97
  • 10

2 Answers2

5

It's not possible to have two types with the same name under the same namespace (this is one reason why namespaces are useful).

A good convention is to have the letter I before interface names, see: IEnumerable, ISerializable...

If you must keep the identical names, you may change the namespace of one of the types and change the using namespace declaration accordingly.

Ofiris
  • 5,907
  • 5
  • 34
  • 57
  • Note that if you *need* namespaces to avoid name clashes, then maybe your names are bad. – Joey Mar 20 '16 at 10:16
  • Absolutely, I see no reason to have the same type name, especially for a class and an interface. – Ofiris Mar 20 '16 at 10:18
  • I was confused with the naming too, but i will change the interface name to IPayment. and change all affected areas. Thanks a lot – Omar.M Mar 20 '16 at 12:24
0

Here is a nice explanation for your question. It's about Java but I think best practices can be similar about naming.

Java Interfaces/Implementation naming convention

fozersahin
  • 98
  • 1
  • 5