Skip to content

Instantly share code, notes, and snippets.

@gaplo917
Created April 3, 2019 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaplo917/d0b200d37c35db546e4315eca4fc64bd to your computer and use it in GitHub Desktop.
Save gaplo917/d0b200d37c35db546e4315eca4fc64bd to your computer and use it in GitHub Desktop.
// Dart
class AAA {
void honey() {}
}
abstract class BBB {
void empire() {}
}
mixin CCC {
void bleed() {}
}
// no way to distinguish class & abstract class unless you looking into details
class D1 extends AAA {}
class D2 extends BBB {}
// no way to distinguish class & abstract class & mixin unless you looking into details
class D3 with AAA, BBB, CCC {}
class D4 implements AAA, BBB, CCC {
@override void honey() {}
@override void empire() {}
@override void bleed() {}
}
// case study: Mixin
class Case1 implements CCC {
@override void bleed() {}
}
// if I know CCC is a mixin by using a different syntax highlight color
// without looking into details, I can immediately know can switch to `with` ONLY but not `extends`
class Case1im with CCC {}
// case study: Abstract class
class Case2 implements BBB {
void empire() {}
}
// if I know BBB is a abstract class by using a different syntax highlight color
// without looking into details, I can immediately switch to use `with` or `extends`
// and I know BBB CANNOT be instantiated directly
class Case2im with BBB {}
class Case2im2 extends BBB {}
// case study: Class
class Case3 implements AAA {
void honey() {}
}
// If I know AAA is a class by using a different syntax highlight color
// without looking into details, I can immediately switch to use `with` or `extends`
class Case3im extends AAA {}
class Case3im2 with AAA {}
// and I know AAA CAN be instantiated directly
void func(){
new AAA();
}
// Consider a complicated structure and you are going to refactor.
// Maybe pull out some code into different modules
// Now, every times I have to cmd + mouse over to check the type before what choices I can be done.
class DDD41 extends AAA with BBB implements CCC {
@override void bleed() {}
}
class DDA42 extends BBB implements AAA, CCC {
@override void honey() {}
@override void bleed() {}
}
class DDA43 extends BBB with CCC implements AAA {
@override void honey() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment