Advertisement
narimetisaigopi

why dart not supports multiple inheritance

Jan 22nd, 2023
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. void main(List<String> arguments) {}
  2.  
  3. // code becomes very complex or to understand in Multiple heritance
  4.  
  5. class MyLogin extends AuthClass with MyRewards, Authentication, Authentication {
  6. @override
  7. logout() {
  8. throw UnimplementedError();
  9. }
  10. }
  11.  
  12. abstract class AuthClass {
  13. logout();
  14. }
  15.  
  16. mixin MyRewards {
  17. int points = 100;
  18. }
  19.  
  20. /**
  21. * User
  22. * Admin
  23. * Moderator
  24. */
  25.  
  26. class User with Authentication {}
  27.  
  28. class Admin with Authentication {}
  29.  
  30. class Moderator with Authentication {}
  31.  
  32. mixin Authentication {
  33. int cibiliPoints = 0;
  34. bool isLogin = false;
  35. setLogin(bool status) {
  36. isLogin = status;
  37. }
  38.  
  39. logout() {
  40. // logout
  41. }
  42.  
  43. getCibilPoints() {}
  44.  
  45. bool isHeElgible() {
  46. if (cibiliPoints > 730) {
  47. return true;
  48. } else {
  49. return false;
  50. }
  51. }
  52. }
  53.  
  54.  
  55.  
  56. /**
  57. * In Dart, a mixin is a way to reuse a class's code in multiple class hierarchies.
  58. * A mixin is defined like a regular class,
  59. * but it is intended to be used as a component of a class rather than a standalone class.
  60. * To use a mixin, a class includes it using the "with" keyword.
  61. * This allows the class that uses the mixin to have access to the mixin's methods and fields,
  62. * as if they were defined in the class itself.
  63. */
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement