Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good naming convention for classes in an inheritance chain? [closed]

Tags:

c#

inheritance

I have three classes in an inheritance chain:

AddActorUITests : WebTestBase : IntegrationTestBase

However I would somehow like to signal by naming convention that WebTestBase inherits from IntegrationTestBase so that the developer writing code in AddActorUITests does not have to check WebTestBaseto verify that it inherits from IntegrationTestBase.

Any suggestions?

like image 805
magnusarinell Avatar asked Oct 16 '25 15:10

magnusarinell


2 Answers

Inheritance is about is-a relationship between the classes. Inheritance should be easy to tell without having to use some kind of convention in the naming.

For instance if you have a Dog which inherits Animal you don't name it DogAnimal. It's already easy to understand what a dog is. Let's look at it from the other perspective. When you code against the Dog class, why is it so important to know that it's an Animal that you need to indicate it in the name? Hungarian notation was abandoned for a reason.

If you still need that notation, aren't you more using inheritance as a toolbox. i.e. you do inheritance just to get some nice features into the sub classes? In that case it's much better that you use composition.

like image 66
jgauffin Avatar answered Oct 18 '25 05:10

jgauffin


If you're using Visual Studio you can use comments?

/// <summary>
/// Inherit <see cref="IntegrationTestBase"> class
/// </summary>
class WebTestBase : IntegrationTestBase
{
    ...
}

and when the user types out the WebTestBase, Visual Studio will automatic show the comments in a popout message.

like image 26
J3soon Avatar answered Oct 18 '25 05:10

J3soon