14

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).

9
  • 8
    I wouldn't think it's an interface, as interfaces start I<CapitalLetter>.... Commented Jan 17, 2012 at 11:29
  • I can't mention the product for obvious reasons but it follows the same capitalisation convention as apple. iPhone, therefore IPhoneClass (appears as an interface) rather than IphoneClass (as you mentioned in your comment and appears as a class). Commented Jan 17, 2012 at 11:31
  • 1
    What @GeorgeDuckett said - a good example would be the Image class. Commented Jan 17, 2012 at 11:32
  • 2
    Just follow the convention, rather than branding. There is no reason to follow branding in code, branding is for user visible text. Commented Jan 17, 2012 at 11:35
  • 1
    @Liath: In that case I would say Iphone to keep class naming consistent. 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. Commented Jan 17, 2012 at 11:35

6 Answers 6

15

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Marking this as the answer because it was given in comments first.
10

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

3 Comments

The name of his product is something like iImpossibleProduct. What do you do then?
Stick to the convention. Use IPhone for the iPhone class, IIPhone for the iPhone interface.
In case of iPhone, i would think to follow the correct convention and not "brand" convention and call such class Iphone instead of IPhone.
4

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.

1 Comment

In my personal opinion, this is just making life difficult for anyone else having to read and understand your code. IDone or ICall would indicate to any developer that they were interfaces. However, I do agree that the naming should indicate the usage of the interface.
2

If the class name begins with an I then this is fine, e.g. Index or Idea are both valid names. IIndex would be a valid interface name.

For help with conventions, you could consider picking up a copy of Code Complete which is an amazing source of guidance in many programmatical aspects.

Comments

0

Can you mangle the name of the class to ensure that it doesn't start with an I?

Typically though, you'd expect that an I that doesn't belong to a word denotes an interface. A class name that starts with I (For example, Interpolator) is fine and not particularly ambiguous.

Comments

0

You can wrap your "bad" called names class with "I" capital letter to other Name For example:

 //"Bad" name class public class IBadClass { public void SomeFuncA(int i) { } public void SomeFunctB(string str) { } } //"Better" name class public class BetterNameClass { private IBadClass _badClass; public BetterNameClass() { _badClass = new IBadClass(); } public void SomeFuncA(int i) { _badClass.SomeFuncA(i); } public void SomeFunctB(string str) { _badClass.SomeFunctB(str); } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.