I'm struggling with how to properly name a specific subset of Properties in
my classes. An example will illustrate it best. Let's say you have a class
named Person with the code below. Each Person instance has a single Address
instance. The Property name is Address, but it returns an instance of type
Address. This results in the code "public Address Address" below when
defining the property. It doesn't make sense to make the property name be
GetAddress since it has a GET and SET. Making the first character of the
property lower case would be confusing too since you could have a field or
variable called "address" which matched it.
Goofy - yes. Any recommendations?
Note - this is just bogus data to make my point, I'm not actually working
with Person and Address classes.
public class Person
{
private string _firstName;
private Address _address;
public Person (firstName)
{
_firstName = firstName;
_address = new Address("123 Washington Dr.");
}
public Address Address
{
get { return _address;}
set { _address = value;}
}
public bool FooBar()
{
//Do something with the address.
Address address = Address;
//Yikes - this creates a local instance of address using the
property Address.
//I agree that this might not be good style regardless of the naming
convention, but it illustrates my problem well.
}
public string FirstName
{
get { return _firstName;}
set { _firstName = value; }
}
}