Skip to content

Instantly share code, notes, and snippets.

@misterfourtytwo
Created July 12, 2020 09:51
Show Gist options
  • Save misterfourtytwo/e8b16c95fe98becfed3c9e78321b590d to your computer and use it in GitHub Desktop.
Save misterfourtytwo/e8b16c95fe98becfed3c9e78321b590d to your computer and use it in GitHub Desktop.
void main() {
A o = A(B(true), B(true), B(true));
print(o);
// т.е. мы вызываем не o.operation(propName) мы делаем o.propName.operation()
o.x.inverse();
print(o);
o.y.inverse();
o.x.truify();
print(o);
}
class A {
B x;
B y;
B z;
A(this.x, this.y, this.z);
@override
String toString() => 'A(x: $x, y: $y, z: $z)';
}
class B {
bool value;
B(this.value);
@override
String toString() => 'B(value: $value)';
void inverse() {
value = !value;
}
}
// достаточно близко к тому, чтобы прописать в самом классе, но возможно у нас
// нет возможности изменить сам класс и это становится полезным
extension MakeTrue on B {
void truify() => this.value = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment