• Advertisement
Sign in to follow this  

[.net] Property naming conventions [solved]

This topic is 3310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just started learning C# a few days ago and I'm a bit confused about naming my properties when they have class types. With get and set accessors from C++, I never had this trouble.
class MyClassWithAnImage
{
    public Image Image // <-- what to name this?
    {
        get { return _image; }
        set { _image = value; }
    }
    private Image _image;
}
GetImage and SetImage don't have this issue. Calling it Picture or Bitmap or something seems like a cop-out. Lower-case image doesn't match other .NET stuff. [Edited by - jdindia on January 21, 2009 7:50:03 PM]

Share this post


Link to post
Share on other sites
Advertisement
While I realise that you can do this, you really shouldn't. Such a thing would be a nightmare for another program to read. Rather, give it a name that describes what the image is supposed to be. If you must keep things simple, then use a term that is the equivolent ie Picture instead of Image.

Granted, that's not much better, but I'm just trying to work within the example.

Share this post


Link to post
Share on other sites
But sometimes Image really is the best name, in which case it's perfectly fine to use it. The .NET framework has many examples of this, such as SolidBrush.Color.

Share this post


Link to post
Share on other sites
I never open up the namespaces so, in your case, my code would look like:

class MyClassWithAnImage
{
public System.Drawing.Image Image
{
get { return _Image; }
set { _Image = value; }
}
private System.Drawing.Image _Image;
}


Much easier for an external reader, as he won't have to guess if Image (the class) is the default System.Drawing.Image or some user-defined class.

Share this post


Link to post
Share on other sites
I suggest calling it something that suggests the role of the image for example.

BackgroundImage (if the image is the background image)

ImageGlyph (if the image is some sort of decoration ...)

or if the class is supposed to be an image wrapper of some sort you can call it

SourceImage

or if the image is both a source and a destination (meaning it is operated upon/changed) then call it

ImageBuffer or simply Canvas

but in the end Image is good also if the role of the property is truly generic.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement