Classes, Interfaces

Cards (7)

  • Factory constructors used when initializing a final variable using logic that can’t be handled in the initializer list.
  • If your class produces objects that never change, you can make these objects compile-time constants.
    To do this, define a const constructor and make sure that all instance variables are final.
    To create a compile-time constant using a constant constructor, put the const keyword before the constructor name.
  • Dart uses initializing formal parameters to simplify the process of assigning a constructor argument to an instance variable. In the constructor declaration, use 'this.propertyName' directly and omit the body.
  • If you need to perform some logic that cannot be expressed in the initializer list, create a factory constructor (or static method) with that logic and then pass the computed values to a normal constructor.
  • If the superclass doesn’t have an unnamed, no-argument constructor, then you must manually call one of the constructors in the superclass.
  • Every class implicitly defines an interface containing all the instance members of the class and of any interfaces it implements.
  • By default, a constructor in a subclass calls the superclass’s unnamed, no-argument constructor. The superclass’s constructor is called at the beginning of the constructor body.