I know that the naming convention for an interface is something like IName
. But what if I am creating an abstract class?
Should I also write an I in front of the class name?
Since in Java, you need to mark an abstract class with the aptly named abstract keyword, I would not include it in the name. In C++, for example, the case is not so clear cut, but at least the compiler will tell you when you incorrectly used an abstract class.
Normally, there is no suffix/prefix used when naming abstract classes, unlike interfaces, which have the prefix "I". Just give your class a name that describes what it is for, in a short precise way.
There should be no need for a name with "Abstract" in business code. For framework code it is a good and helpful convention to have interface -> abstract -> default.
Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).
As opposed to Oracles Java coding conventions, there is no "The" naming convention for C++.
If you are working on a project for some company you should follow their naming conventions. If there are no documented conventions - look around the code base and try to follow the swarm, consistency is the key.
If you are starting something on your own, many find google's c++ coding conventions as a good start.
If you are trying to adhere to a specific naming convention, please name it. As the other answer explains, there is no global "C++ Rule" regarding naming conventions.
If you are using Hungarian notation, I believe that the convention is indeed to prefix 'I' as you did for 'IName'.
Note: Whilst there is no "interface" as such in C++, you can define classes with only pure virtual methods and no member variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With