Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Dart type


May 23, 2021 Dart Code style guide


Table of contents


Type

If a simple function can meet your needs, you should avoid declaring an abstract class with only a single member. I n addition to Java, Dart has top-level functions, closures, and very beautiful syntax highlights. I f you need something similar to a callback, you only need to use one function. I f you define a class that has only one member and its name doesn't mean call like call or invoke Then defining a function directly would be a better choice:

typedef bool Predicate(item); // good
abstract class Predicate {
    bool test(item);  
}// bad