Search code examples
javamethod-chaining

Java method().method().method(); How to do this?


For example how do I do this?

getServer().getManager().registerNewUser(arguments);

and

getServer().getStats().user(arguments);

Stuff like this, I've tried searching the web but I cant find any tutorials on this,so I'm asking here.


Solution

  • In OOP, in general, this concept is called class composition more on this you can find it here https://en.wikipedia.org/wiki/Object_composition

    Also for java and the difference between Composition and inheritance https://www.baeldung.com/java-inheritance-composition