dimanche 25 novembre 2018

Which of these is the correct way to compose interfaces?

Let's say I have a business entity called a "dude" which has the following characteristics:

  • Every dude has a first name
  • Every dude has an age
  • Some dudes have a last name
  • The idea of a "last name" only makes sense in the context of a dude; in other words, I don't expect it to be used in any other context

Option 1:

interface IDude
{
   string FirstName { get; }

   int Age { get; }
}

interface IDudeWithLastName : IDude
{
   string LastName { get; } 
}

Option 2:

interface IDude
{
   string FirstName { get; }

   int Age { get; }
}

interface ILastNamed
{
   string LastName { get; } 
}

interface IDudeWithLastName : IDude, ILastNamed
{
}

Aucun commentaire:

Enregistrer un commentaire