Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for an abstract class?

Tags:

c++

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?

like image 561
Maik Klein Avatar asked May 07 '13 23:05

Maik Klein


People also ask

How should you name an abstract class?

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.

What do you name an abstract base 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.

Should abstract classes be named abstract?

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.

What is naming convention for classes?

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


2 Answers

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.

like image 65
Zelix Avatar answered Oct 15 '22 14:10

Zelix


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.

like image 31
OMGtechy Avatar answered Oct 15 '22 14:10

OMGtechy