开发者

C#: Naming convention for Nested classes, and proper implementation?

I wonder if there is a standard for naming the "concrete" class and the instance.

For example, I have currently a class called Test and its instance is called is called Test as well. I think this is bad.

Is there some sort of standard to name the concrete class and its instance? The instance needs to be Test but the concrete I have no idea what to do; name it TestConcrete?

What does Microsoft do in this situation?

Basically the concrete class is ONLY for use in the Product class to support Nested classes, it will never be instantiated from outside.

Here is my class. I presume I am doing this correct? I am creating the instance of Test inside the constructor of Product.

I don't want to get into bad habits and I am going to be doi开发者_如何学编程ng a lot of these, and Test (concrete) and Test (instance) is probably a bad idea!

public class Product    {
    public int Id { get; set; }

    private Test Test { get; set; }


    public Product()
    {
        Test = new Test();
    }
}


It's not without precedent, I think you can find

  Color  Color { get; set; } 

in the library, and some more like that.

But best way around it is to think of a more specific name, that is Domain driven. Something like

  private Test TestResults { get; set; }

or

  private TestData  Test { get; set; }


These are my Guidelines:

public abstract class Test
{
    public void FooBar() // Method, capitalization, PascalCase
    {
         Person fatherFigure = new Person(); // Class instance, lowercase first letter, camelcase rest.

    }

    public string Name {get; set; } // Property, capitalization, PascalCase

    private string PrivateName {set; set; } // Private property, capitalization, camelcase

    public string someField; // Field, lowercase first letter, camelcase

    private string _someField; // Private member, prefix with _
}

These are only my own opinions. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜