What is the best way to name two classes that describe the same object, but where one of those classes does not hold the complete information? And should I make one of the classes inherit from the other?
I want to have (for the sake of example) an API that gets all people to display a list of names, and then when a person has been selected, another API that gets the detailed content for that person.
Here is an example of the classes I am currently using, and demonstrating my current decisions: the naming conventions, and that one should derive from the other.
public class PersonBase
{
public int PersonId { get; set; }
public string Name { get; set; }
}
public class Person : PersonBase
{
public Date DateOfBirth { get; set; }
// Other properties...
}
EDIT: The reason I have chosen to separate into two classes for the same entity is because the database query for the complete Person
is a lot more complex/intensive, and therefore I want a lightweight version that is used when searching for a particular person in a list.
Note that what I have called PersonBase
actually contains some other properties that are used to filter on (you could imagine IsManager
or similar), so in my opinion it does represent the person, but simply does not have the full information.
PersonBase
has a methodgetDetails()
which returnsOptional<Details>
.