Why is Dart Datetime.parse not a factory constructor?

The Dart Datetime class has several named constructors, but is DateTime.parse()not one of them. Instead, it DateTime.parse()is a static method that returns a DateTime. For me, this makes sense as a constructor (since you are generating a new DateTime object in a manner not too different from the constructor Datetime.utc()).

The theories that I came up with should reflect the fact that int.parseit is not a constructor or allows you to simplify the chain (you do not need to use a cascading operator with a static method). But perhaps there is another reason that I do not think about. Does anyone know why they did not make it a named constructor?

+4
source share
1 answer

More explanation for the same change for Uri.parse: http://permalink.gmane.org/gmane.comp.lang.dart.general/17081

"parse" is special. The question arises: do you see that parsing does something and ends up giving you the result, or do you see the line as data to create a new element. If you see this as before, then parsing should be a static function. If you see a string as data, then it should be a named constructor.

And then, of course, there is a sequence.

+5
source

Source: https://habr.com/ru/post/1570078/


All Articles