In C#, it's common to have methods like this:
public IPerson GetPerson()
{
// do stuff
return new Person(..);
}
where "IPerson
" is an interface used by Person
, SpecialPerson
, etc. In other words, although the method above returns a Person
, a strategy pattern could be implemented such that a SpecialPerson
is returned in lieu of a Person
, provided they all use the IPerson
interface.
Is this sort of thing possible in Java?