abstract class Feature { abstract color : string ; abstract bark ( ) ; } enum animalType { 'cat' , 'dog' } interface c { } type a = c ; class Cat extends Feature { color = "白色" ; bark ( ) { console . log ( `${ this . color } 喵喵喵` ) ; } } class Dog extends Feature { color = "黑色" ; bark ( ) { console . log ( `${ this . color } 汪汪汪` ) ; } } class Animal { createAnimal ( type ) { switch ( type ) { case animalType . dog : return new Cat ( ) ; case animalType . dog : return new Dog ( ) ; } } } const animal = new Animal ( ) ; const cat = animal . createAnimal ( animalType . cat ) ; const dog = animal . createAnimal ( animalType . dog ) ; cat . bark ( ) ; dog . bark ( ) ; export default Animal ;