Factory Constructor

We create an abstract Shape. We force class that conforms to this abstraction a getArea() and name.
In order to generate instances according to json data, we implement a factory constructor called fromJson.

It takes in a JSON object, and then returns a Square, or a Circle.

Factory constructors can return instances of the subclass.
But standard constructors can ONLY return instances of the current class.

Notice that in the abstract class Shape below, we actually can return subclass Square and Circle.

shape.dart

We conform to Shape by implementing name and getArea().
We then create a constructor with required param side.

Circle.dart

We conform to Shape by implementing name and getArea.
We then create a constructor by having required param side.

Square.dart

Finally, we use it like so: