Open utterances-bot opened 3 years ago
There is no info in this article how to make method chaining if you don't care about inheritance. Here is a example, that can be useful for beginners:
// new Simon().sleep().talk().work().talk();
class Simon {
public var energy = 0;
public function new() {}
public function sleep():Simon {
energy = 2;
return this;
}
public function talk():Simon {
trace('My energy is $energy');
return this;
}
public function work():Simon {
energy--;
return this;
}
}
Method chaining / Fluent interface - Design patterns - Haxe programming language cookbook
This is an example of the Method chaining design pattern in Haxe.
https://code.haxe.org/category/design-patterns/method-chaining-fluent-interface.html