Skip to content

Instantly share code, notes, and snippets.

@MelvinRB27
Created October 4, 2023 16:22
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 MelvinRB27/858f0d3b16b074cf8d17ff00aa3001ad to your computer and use it in GitHub Desktop.
Save MelvinRB27/858f0d3b16b074cf8d17ff00aa3001ad to your computer and use it in GitHub Desktop.
Extends, Implements
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