_This issue was originally filed by luciandog...@ymail.com_
Please implement partial classes in Dart.
_This comment was originally written by adrian.avil...@gmail.com_
You can already split classes in Dart with part files, that would be the equivalent.
_Set owner to @gbracha._
_Removed Type-Defect label._
_Added Type-Enhancement, Area-Language, Triaged labels._
We've discussed this on the mailing list. You can use parts for large libraries. You can define multiple mixins and combine them. We do not need this extra sugar.
_Added AsDesigned label._
Link to misc@ discussion Jan 2013 - https://groups.google.com/a/dartlang.org/d/topic/misc/KTuJ_Z6O1oQ/discussion
Mixins are great to encourage reuse, but the there are arguments for partial classes that cannot be covered by mixins: generating code that includes constructors, for instance.
For example:
// mycode.dart
library mycode;
part 'mycode.g.dart';
class Person {
String firstName, lastName;
}
// mycode.g.dart
part of mycode;
partial class Person {
Person.fromJson(json) =>
new Person()
..firstName = json['firstName']
..lastName = json['lastName'];
toJson() => {'firstName': firstName, 'lastName': lastName};
}
_Added Triaged label._
_Added Accepted label._
_This comment was originally written by hangglide...@gmail.com_
We donot need this extra sugar.
- 1
Not being able to extend classes through partial implementation files is PITA and makes some scenarios really hard to achieve when it comes to autogenerated code. This is even more important to flutter because it doesn't support reflection (or whatever it's called in dart world) and you have either write or autogenerate code (i.e. json (de)serialization).
Sadly this issue isn't getting any love for more than 3 years.
You might want to check out several recent related issues: dart-lang/language#40, dart-lang/language#41, dart-lang/language#42, dart-lang/language#177, dart-lang/language#309.
Granted, C# style partial classes are not equivalent to any of these, but they are concerned with mechanisms for extending existing classes.
@eernstg Thanks for the info, hopefully they will come out with something comparably useful.
Most helpful comment
Link to misc@ discussion Jan 2013 - https://groups.google.com/a/dartlang.org/d/topic/misc/KTuJ_Z6O1oQ/discussion
Mixins are great to encourage reuse, but the there are arguments for partial classes that cannot be covered by mixins: generating code that includes constructors, for instance.
For example:
// mycode.dart
library mycode;
part 'mycode.g.dart';
class Person {
String firstName, lastName;
}
// mycode.g.dart
part of mycode;
partial class Person {
Person.fromJson(json) =>
new Person()
..firstName = json['firstName']
..lastName = json['lastName'];
toJson() => {'firstName': firstName, 'lastName': lastName};
}
_Added Triaged label._