Created with <3 with dartpad.dev.
Created
October 4, 2023 16:22
-
-
Save MelvinRB27/858f0d3b16b074cf8d17ff00aa3001ad to your computer and use it in GitHub Desktop.
Extends, Implements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final ghero = GoodHero(name: 'Iron Man', power: 'Rich', isAlive: false); | |
print(ghero); | |
final bhero = BadHero(name: 'Flash', power: 'Fast', isAlive: true); | |
print(bhero); | |
} | |
enum HeroType { good, bad } | |
abstract class Hero { | |
String name; | |
String power; | |
bool isAlive; | |
HeroType type; | |
Hero( | |
{required this.name, | |
required this.power, | |
required this.isAlive, | |
required this.type}); | |
void getHero(); | |
} | |
class GoodHero extends Hero { | |
GoodHero({required String name, required String power, required bool isAlive}) | |
: super(name: name, power: power, isAlive: isAlive, type: HeroType.good); | |
@override | |
void getHero() {} | |
@override | |
String toString() { | |
return 'Name: $name \n Power: $power \n IsAlive: $isAlive \n Type: $type'; | |
} | |
} | |
class BadHero implements Hero { | |
@override | |
String name; | |
@override | |
String power; | |
@override | |
bool isAlive; | |
@override | |
HeroType type = HeroType.bad; | |
BadHero({required this.name, required this.power, required this.isAlive}); | |
@override | |
void getHero() {} | |
@override | |
String toString() { | |
return 'Name: $name \n Power: $power \n IsAlive: $isAlive \n Type: $type'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment