Declaring an interface to be used as a type constraint
First, we will create a Sociable
interface to specify the requirements that a type must meet in order to be considered a potential member of a party, that is, a sociable animal in our application domain. Then, we will create a SociableAnimal
abstract base class that implements this interface, and then, we will specialize this class in three concrete subclasses: SocialLion
, SocialParrot
, and SocialSwan
. Then, we will create a Party
class that will be able to work with instances of any class that implements the Sociable
interface through generics. We will create two new classes that will represent specific exceptions. We will work with a party of sociable lions, one of sociable parrots, and another of sociable swans.
The following UML diagram shows the interface, the abstract class that implements it, and the concrete subclasses that we will create, including all the fields and meth:
The following lines show the code for the Sociable
interface...