Skip to content

Instantly share code, notes, and snippets.

abstract class PlanetVisitor {
void visit({Planet planet});
}
abstract class Planet {
void accept({PlanetVisitor visitor});
}
class MoonJedah extends Planet {
@override
abstract class PrintStrategy {
String print(String string);
}
class Printer {
PrintStrategy _strategy;
Printer({PrintStrategy strategy}) : _strategy = strategy;
String print(String string) {
return _strategy.print(string);
abstract class State {
bool isAuthorized({Context context});
String userId({Context context});
}
class Context {
State _state = new UnauthorizedState();
bool get isAuthorized => _state.isAuthorized();
@thonglinhma
thonglinhma / factory-method.dart
Last active April 20, 2018 09:03
The factory pattern is used to replace class constructors, abstracting the process of object generation so that the type of the object instantiated can be determined at run-time.
abstract class Currency {
String sysmbol();
String code();
}
class Euro extends Currency {
@override
String sysmbol() {
return "€";
}
abstract class Switch {
Appliance appliance;
void turnOn();
}
abstract class Appliance {
void run();
}
class RemoteControl extends Switch {