For example, a custom component needs to know what String to paint as its title.
Overriding
CustomComponent c = new CustomComponent(){
@Override
public String getTitle(){
return "A given title";
}
};
Fields
CustomComponent c = new CustomComponent()
c.setTitle("A given title");
Using the first method, I don’t need to create a String field in CustomComponent, but the code is much cleaner. Is there a strongly preferred / suggested way, and if so why?
Note that this is just a simple example.
Thanks
If all CustomComponents have a simple string title then a data field is the way to go.
Move to a method once things become a bit more complicated (e.g. the title needs subclass specific info [like how many children it “owns”]).