I'm trying to ascertain whether the use of multiple references to the same property is code smell / an anti-pattern, based on the needs of the organisation.
As an example, consider:
abstract class Person {
public string Title { get; set; }
public string Forename { get; set; }
public string MiddleNames { get; set; }
public string Surname { get; set; }
public string GivenName { get { return Forename; } set { Forename = value; } }
public string FamilyName { get { return Surname; } set { Surname = value; } }
public string FirstName { get { return Forename; } set { Forename = value; } }
public string LastName { get { return Surname; } set { Surname = value; } }
}
As you can see, I have several other properties, (kind of) aliasing or giving alternate names to properties in the object, but basically repeating exactly the functionality of the base property without exception.
The reasons behind this is down to the naming conventions utilised in different areas of the organisation; it's providing multiple ways of addressing the same information, allowing each different area to use their preferred method of access. Because each of the other properties reference the base property, any programmatic changes only need to be included in the said base property.
And so to clarify...
@GregBurghardt has kindly posted alternatives to my conundrums, but I feel that I must qualify one of my statements a little more.
In VB.NET I can quite happily code interfaces into my classes but use alternative names in the actual member implementation, like so...
Public Interface IPerson
Property Forename() As String
Property Surname() As String
End Interface
Public Class BillingPerson
Implements IPerson
Public Property GivenName() As String Implements IPerson.Forename
...
Public Property FamilyName() As Int32 Implements IPerson.Surname
....
End Class
Notice, here, that I've used a different property name for the (VB) property, but still implemented the true name of the interface (e.g. Public Property GivenName () As String Implements IPerson.Forename). This means that I can reference my BillingPerson
class, despite the obvious property name differences, using the interface...
'Define our interface type object here...
Dim myP As IPerson = New BillingPerson()
'Assign values directly to the interface members...
myP.Forename = "Fred"
myP.Surname = "Bloggs"
'Output the interface members...
Console.WriteLine(myP.Forename & " " & myP.Surname)
...or I can refer to the original class directly....
'Define our BillingPerson object here...
Dim myP As BillingPerson
'Assign values directly to the interface members...
myP.GivenName = "Fred"
myP.FamilyName = "Bloggs"
'Output the interface members...
Console.WriteLine(myP.Forename & " " & myP.Surname)
Using this methodology, my problem would be very short-lived , and I'd be able to create as many classes based on the interface as I need.
This doesn't appear to work the same way in C#, however, where I can't directly alias the name of the interface members.
Person
, each with their org-specific terms, work (e.g.FamilyPersonView
usingFamilyName
property)? It'd simply refer toPerson.Name
internally (i.e.Person
instance is the model in the MVC-like design (the controller is the client)).