Skip to content

Object Template Language Enhancement #99

Closed
@DartBot

Description

@DartBot

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.

  1. Supports safe lazy singleton objects.
  2. Namespaces typedefs, enums and standalone functions which are not always desirable to be at toplevel. (Acts as a lazy init'd static module)
  3. Separate grouping of static methods from class template. Alleviates the need of the 'static' keyword for static methods.
  4. Does not require special syntax and special treatment for named constructors.
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-not-plannedClosed as we don't intend to take action on the reported issuetype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions