September 2019
Beginner
512 pages
12h 52m
English
Another useful syntax in Dart is the factory constructor, which helps to apply the factory pattern, a creation technique that allows classes to be instantiated without specifying the exact resulting object type. Suppose we have the following descendants of the Person class:
class Student extends Person { Student(firstName, lastName): super(firstName, lastName);}class Employee extends Person { Employee(firstName, lastName): super(firstName, lastName);}
As you can observe, the descendant classes are still almost the same as the Person class, as they do not yet add any specific functionalities.
We can define a factory constructor on the Person class to instantiate the corresponding class based on the required type argument: ...
Read now
Unlock full access