I've seen this present in several codebases, and more recently, in Pytorch's codebase, e.g., here https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/core/TensorBase.h#L490-L492
TensorOptions options() const {
return TensorOptions().dtype(dtype())
.device(device())
.layout(layout());
}
where a member function is set up to to return a chain of other member functions, and each member function returns the same type (in this case, it's TensorOptions
).
I was wondering if there's a particular name for this type of OOP design, and what the advantage of it is?