Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# class names starting with an I

I am writing a class where the name starts with an I (because that's the name of the product we're integrating with - can't change).

Convention states that class names have a capital letter to start, however in this case it would appear to the consumer as an interface.

Is there any documentation guiding developers on the correct approach here? In addition what happens if I do need to implement and interface - should it be IiProduct/IIProduct?

Edited to Add:

I can't mention the product for obvious reasons but it follows the same capitalisation convention as apple. iPhone, therefore IPhoneClass (follows their branding but appears as an interface) rather than IphoneClass (which follows convention rather than branding).

like image 437
Liath Avatar asked Jan 17 '12 11:01

Liath


3 Answers

If the product name is for example iPhone, then in that case I would call the classIphone to keep class naming consistent. The interface would be IIphone, which doesn't look great, but is clear in its meaning (as it follows convention).

I'm sure people using the class would be more upset if they thought it was an interface, than if it wasn't capitalized as the product is to follow convention.

like image 70
George Duckett Avatar answered Oct 11 '22 07:10

George Duckett


Interface starts with I as a prefix and then Interface name using capital letter. So interface will be IImposibleProduct and class will be ImposibleProduct.

like image 25
Alex Dn Avatar answered Oct 11 '22 07:10

Alex Dn


I follow this convention for interface.

  1. Find the most significant method in the interface.
  2. Add able suffix with it.
  3. Capital the first letter.
  4. Add I prefix

See the example

interface ICallable{
    public void call();
}

ICallable = I + CapitlizeFirstLetter(call+able)

I think most developers follow these convention. From that point of view IClass, IDone, ICall , IncomeTax etc are not an interface. But IClassable, ICallable, ITaxable etc respectively are interface.

like image 28
Shiplu Mokaddim Avatar answered Oct 11 '22 05:10

Shiplu Mokaddim