views:

448

answers:

5

Imagine I created this class:

 public class ColoredPolygon
 {
     public Point[] Vertices { get; set; }
     public Brush Brush { get; set; }
 }

Inside Visual Studio isn't difficult to see which "Brush" is the class and which is the property. But something tells me that is not a best practice to name a property after its class. How would you name this property?

Update One more question about naming: How do you name Arrays? With the plural or with singular?

+4  A: 

How about FillBrush?

RichieHindle
Good Inspiration. I changed to Filling.
Jader Dias
.. or just Fill :)
cwap
"Filling" sounds like it belongs inside a donut. FillBrush is a better name than Filling.
Kyralessa
Thanks @Meeh and @Kyralessa
Jader Dias
A: 

As well as FillBrush, mentioned in another answer, you might consider adding a way to set just the fill Color, so that the user won't have to construct a brush just to set a solid color fill.

Kyralessa
+5  A: 

FillBrush is a good, descriptive name (and I've upvoted) but, honestly, don't worry about it until it actually becomes a real problem. In your case, it may not be the best name, but if it were the best name, I'd keep it until the context dictated otherwise. I have a few examples where the name of the class and the property is the same, but since the property usually is qualified by a variable name (or this.), I don't worry too much about it.

I find the following pretty readable:

var poly = new ColoredPolygon();
poly.Brush = Brushes.Green;
tvanfosson
+18  A: 

I would call it Brush. The Design Guidelines for Developing Class Libraries actually says:

Consider giving a property the same name as its type

(in the section about naming Type members). The text following the statement suggests to do this for properties that are of Enum types, but you can find plenty of examples of this approach for other types of objects in the .NET framework, for instance the Brush and Color properties of the Pen class.

Nothing to worry about, if Brush is a descriptive name for your property you should use that name, especially since it would even follow the naming pattern that you can see within the framework.

Fredrik Mörk
A: 

Regarding Fredrik's suggestion (Brush Brush) and also MS's naming suggestions, you may consider giving a property the same name as its type, but you cannot always do it. If for example you have a public enum called Something defined in a class, then that class cannot also have a property called Something.

You can have a property called Brush, presumably because Brush is defined in a different namespace/class and the compiler is then smart enough to figure out which Brush you mean.

AAT