How to define interfaces in Dart?

前端 未结 4 1662
耶瑟儿~
耶瑟儿~ 2021-02-01 12:52

In Java, I might have an interface IsSilly and one or more concrete types that implement it:

public interfa         


        
4条回答
  •  遇见更好的自我
    2021-02-01 12:54

    In Dart, every class defines an implicit interface. You can use an abstract class to define an interface that cannot be instantiated:

    abstract class IsSilly {
        void makePeopleLaugh();
    }
    
    class Clown implements IsSilly {
    
        void makePeopleLaugh() {
            // Here is where the magic happens
        }
    
    }
    
    class Comedian implements IsSilly {
    
        void makePeopleLaugh() {
            // Here is where the magic happens
        }
    
    }
    

提交回复
热议问题