Created
July 12, 2020 09:51
-
-
Save misterfourtytwo/e8b16c95fe98becfed3c9e78321b590d to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
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