interface Feature { color : string ; bark ( ) : void ; } type name = 'cat' | 'dog' ; class Cat implements Feature { color = "白色" ; bark ( ) { console . log ( `${ this . color } 喵喵喵` ) ; } } class Dog implements Feature { color = "黑色" ; bark ( ) { console . log ( `${ this . color } 汪汪汪` ) ; } } class Animal { createAnimal ( type ) { switch ( type ) { case 'cat' : return new Cat ( ) ; case 'dog' : return new Dog ( ) ; } } } const animal = new Animal ( ) ; const cat = animal . createAnimal ( 'cat' ) ; const dog = animal . createAnimal ( 'dog' ) ; cat . bark ( ) ; dog . bark ( ) ; export default Animal ;