The IPerson interface

According to our requirements, the class instance that is returned by the Factory must be able to do two things—print the category of the person in the required format, and tell us whether they can sign contracts. Let's start by defining an enum and an interface to satisfy this requirement:

enum PersonCategory { 
    Infant, 
    Child, 
    Adult, 
    Undefined 
} 
 
interface IPerson { 
    Category: PersonCategory; 
    canSignContracts(): boolean; 
    printDetails(); 
} 

We start with an enum to hold the valid values for a PersonCategory, that is, Infant, Child, Adult, or Undefined. The Undefined enum value is used to indicate that we have not categorized the Person as yet. We then define an interface named IPerson that holds all of the functionality that is common to each type of person. This includes their Category, a function named canSignContracts that returns either true or false, and a function to print out their details, named printDetails.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.109.151