Just a little question i had trouble googling the answer too.
Is it possible to do something like..
bomb.setX(newx)
.setY(newy);
bomb is just an object with methods setX and setY, i was just wondering if you could string method invocations together somehow to save space and make things more human readable? I’m sure i’ve seen something similar before..
Oh cruicially i’m working in java here. Though I would be interested to know if such a shorthand exists in c++ too if anyone knows 🙂
If
setXreturns the bomb, yes.Call this fluent interface. To achieve this fluent interface it is using a technique called method chaining.
In software engineering, a fluent interface (as first coined by Eric Evans and Martin Fowler) is an implementation of an object oriented API that aims to provide for more readable code.
A fluent interface is normally implemented by using method chaining to relay the instruction context of a subsequent call (but a fluent interface entails more than just method chaining). [1]