Created
November 25, 2019 13:12
-
-
Save eernstg/7bbf1dd751a4277fdfcb6c94564bb4fe to your computer and use it in GitHub Desktop.
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
abstract class Person { | |
String name; | |
String address; | |
} | |
class DelegatorPerson implements Person { | |
DelegateePerson delegatee; | |
DelegatorPerson(this.delegatee); | |
String get name => delegatee.name(this); | |
set name(String value) => delegatee.nameSet(this, value); | |
String get address => delegatee.address(this); | |
set address(String value) => delegatee.addressSet(this, value); | |
toString() => "$name, $address"; | |
} | |
abstract class DelegateePerson { | |
DelegateePerson next; | |
DelegateePerson(this.next); | |
String name(Person self); | |
void nameSet(Person self, String value); | |
String address(Person self); | |
void addressSet(Person self, String value); | |
} | |
class DelegateeAddress extends DelegateePerson { | |
String _address; | |
DelegateeAddress(DelegateePerson next, this._address): super(next); | |
String name(self) => next != null ? next.name(self) : throw "'name' unimplemented"; | |
void nameSet(self, value) => next != null ? next.nameSet(self, value) : throw "'name=' unimplemented"; | |
String address(self) => _address; | |
void addressSet(self, value) => _address = value; | |
} | |
class DelegateeName extends DelegateePerson { | |
String _name; | |
DelegateeName(DelegateePerson next, this._name): super(next); | |
String name(self) => _name; | |
void nameSet(self, value) => _name = value; | |
String address(self) => next != null ? next.address(self) : throw "'address' unimplemented"; | |
void addressSet(self, value) => next != null ? next.addressSet(self, value) : throw "'address=' unimplemented"; | |
} | |
void main() { | |
var house = DelegateeAddress(null, "5th Anevue"); | |
var adamName = DelegateeName(house, "Adam"); | |
var eveName = DelegateeName(house, "Eve"); | |
var adam = DelegatorPerson(adamName); | |
var eve = DelegatorPerson(eveName); | |
print("$eve & $adam."); | |
eve.address = "Broadway"; | |
print("$eve & $adam."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment