Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you resolve the common naming collision between type and object?

Since the standard c# convention is to capitalize the first letter of public properties, the old c++ convention of initial capital for type names, and initial lowercase for non-type names does not prevent the classic name collision where the most obvious object name matches the type name:

class FooManager
{
    public BarManager BarManager { get; set; } // Feels very wrong.
                                               // Recommended naming convention?
    public int DoIt()
    {
         // 1st and 2nd Bar Manager are different symbols 
         return BarManager.Blarb + BarManager.StaticBlarb;                                                                          
    }
}

class BarManager
{
    public        int Blarb { get; set; }
    public static int StaticBlarb { get; set; }
}

It seems to compile, but feels so wrong. Is there a recommend naming convention to avoid this?

like image 331
Catskul Avatar asked Mar 12 '10 18:03

Catskul


1 Answers

Having a type and a property with the exact same name isn't uncommon. Yes, it looks a little weird, but renaming properties to avoid this clash looks even weirder, admittedly.

Eric Lippert had a blog post on this exact topic.

There is no ambiguity for the compiler, however.

like image 191
Joey Avatar answered Nov 15 '22 15:11

Joey