Closed
Description
This issue was originally filed by [email protected]
Please provide any additional information below.
Add an additional template 'object' with similar semantics as Scala.
This one concept subsumes and simplifies several current concepts in Dart.
- Supports safe lazy singleton objects.
- Namespaces typedefs, enums and standalone functions which are not always desirable to be at toplevel. (Acts as a lazy init'd static module)
- Separate grouping of static methods from class template. Alleviates the need of the 'static' keyword for static methods.
- Does not require special syntax and special treatment for named constructors.
- Supports near equivalent benefit for factory constructors without requiring special syntax.
All with just one concept.
class Point {
Point (x, y) ...
...
}
object Point {
// static methods, variables
// factory methods
Point _zero = new Point (0,0) // singleton zero value
Point zero () => _zero
Point apply (x,y) ...
}
new Point (1,2) // ctor
Point.zero () // named
Point (3, 4) // factory