Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad practice to have identically named Non-Generic and Generic classes?

To my surprise i'm able to do this:

public abstract class BaseComponent
{
    protected GameObject GameObject;

    internal BaseComponent(GameObject gameObject)
    {
        GameObject = gameObject;
    }
}

public abstract class BaseComponent<TComponent, TManager> : BaseComponent
where ...
{

}
  1. Is naming my 2 classes the same bad practice?
  2. Is there a standard naming convention in this case?
like image 944
George Duckett Avatar asked Feb 03 '26 15:02

George Duckett


2 Answers

Is naming my 2 classes the same bad practice?

No.

Is there a standard naming convention in this case?

The same name is fine. cf. IEnumerable and IEnumerable<T>.

To my surprise i'm able to do this:

Why is it a surprise? It's intuitive, and is standard in the framework.

like image 96
jason Avatar answered Feb 05 '26 03:02

jason


It is comparable to method overloading. Instead of having a lot of different method names for methods doing basically the same thing, the overloads help to create order. However, you should not abuse it. Classes, interfaces and methods with the same name really should implement the same idea with different flavors. Otherwise, it would be very confusing.

like image 35
Olivier Jacot-Descombes Avatar answered Feb 05 '26 05:02

Olivier Jacot-Descombes