Put static builder/factory methods on the interface types that they return
See original GitHub issue_This issue is taken from https://github.com/SpongePowered/SpongeAPI/pull/2275#issuecomment-739912355_
Currently, in order to build a TextComponent, you must call Component.text(*), there is no way to know, based on the TextComponent interface itself, how to construct such an object.
Pre 4.0 gold, TextComponent actually had builder and of methods, which were removed in favour of static methods on Component named text(*). From a strictly Sponge point of view, this works against the design of our API and so this works against us. I also accept that this library is not Sponge and so I’m not asking for of to return, as TextComponent.text(String) is a totally reasonable construct - I understand that you made this deicions to use text() et. al. as methods to support static imports. However, taking the factory method off TextComponent and putting it on to Component has caught a few of us out - personally, I feel Component.text(...) is the wrong place for this to go as the type you’re advertising this to be is a TextComponent.
Futher, from the Sponge point of view, where Text.of() in API 7 was a (admittedly bad) thing, that is the first place that people are going to start looking. Putting the factory and (renamed) builder methods back on TextComponent will aid IDE autocompletion and we’re onto a winner - people will look for that.
Thus, I propose that the text()/textBuilder()/whatever factory/builder methods are put onto TextComponent as these methods construct TextComponents, not merely Components, and I suggest a similar setup for other component types.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
I do not think we’ll be moving these methods, and I am hesitant to duplicate them in their types for a number of reasons:
Componenttypes since moving the factory methods over to the rootComponentinterfaceI am going to close this issue as
wontfixfor now, due to the above discussion.