Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.59 KB | None | 0 0
  1. void main() {
  2.   doSmth(MongoDB());
  3. }
  4.  
  5. void doSmth(DB db) {
  6.   final success = db.create('Ahmed', 'name');
  7.   if (success)
  8.     print('Succeeded');
  9.   else
  10.     print('Failed');
  11. }
  12.  
  13. enum EatingType { meat, plant, both }
  14.  
  15. abstract class DB {
  16.   bool create(String value, String key);
  17.   String read(String key);
  18.   bool update(String newValue, String key);
  19.   bool delete(String key);
  20. }
  21.  
  22. class MongoDB implements DB {
  23.   @override
  24.   bool create(String value, String key) => false;
  25.  
  26.   @override
  27.   bool delete(String key) => true;
  28.  
  29.   @override
  30.   String read(String key) => 'Mohammed';
  31.  
  32.   @override
  33.   bool update(String newValue, String key) => false;
  34. }
  35.  
  36. class FirestoreDB implements DB {
  37.   @override
  38.   bool create(String value, String key) {
  39.     //lsdjflk
  40.     //lkjsdf
  41.     //lkjadsf
  42.     //lksjdf
  43.  
  44.     return true;
  45.   }
  46.  
  47.   @override
  48.   bool delete(String key) => false;
  49.  
  50.   @override
  51.   String read(String key) => 'Ahmed';
  52.  
  53.   @override
  54.   bool update(String newValue, String key) => true;
  55. }
  56.  
  57. abstract class Animal {
  58.   Animal(this.age, this.eatingType, this.legsCount);
  59.   int age;
  60.   final EatingType eatingType;
  61.   final int legsCount;
  62.  
  63.   String speak();
  64.  
  65.   @override
  66.   String toString() =>
  67.       'Age: $age, Eating Type: $eatingType, Legs Count: $legsCount, and says: ${speak()}';
  68. }
  69.  
  70. class Cat extends Animal {
  71.   Cat(int age) : super(age, EatingType.meat, 4);
  72.  
  73.   @override
  74.   String speak() => 'Meoow';
  75.  
  76.   String play() => 'Playing smth';
  77. }
  78.  
  79. class Cow extends Animal {
  80.   Cow(int age) : super(age, EatingType.plant, 4);
  81.  
  82.   @override
  83.   String speak() => 'Mooo';
  84. }
  85. z
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement