In Java, I might have an interface IsSilly
and one or more concrete types that implement it:
public interface IsSilly {
public void makePeopleLaugh();
}
public class Clown implements IsSilly {
@Override
public void makePeopleLaugh() {
// Here is where the magic happens
}
}
public class Comedian implements IsSilly {
@Override
public void makePeopleLaugh() {
// Here is where the magic happens
}
}
What's the equivalent to this code in Dart?
After perusing the official docs on classes, it doesn't seem that Dart has a native interface
type. So, how does the average Dartisan accomplish the interface segregation principle?
In Dart there the concept of implicit interfaces.
So your example can be translate in Dart like this :
In Dart, every class defines an implicit interface. You can use an abstract class to define an interface that cannot be instantiated:
The confusion usually is because doesn't exist the word "interface" like java and another languages. Class declarations are themselves interfaces in Dart.
In Dart every class defines an implicit interface like others says.So then... the key is: Classes should use the implements keyword to be able to use an interface.