I do not know how to describe my problem, so I will give you a brief explanation.
I want to create a program in which the user can select a language, and then the text will be printed in that language. I am currently thinking of something like this:
// Super | class Language; // Sub | --- class German; // Sub | --- class English; if(UserChoseEnglish()) language = new English(); else language = new German();
English and German have the same public static final fields, so I can use language.anyMethod(); which is set by the userβs choice. AFAIK, you cannot redefine fields, so I thought about packing all the fields in abstract methods (in a superclass) that return only a value and redefine them.
public abstract class Language { public abstract String thanks(); } public class English extends Language { @Override public String thanks() { return "Thanks!"; } } public class German extends Language { @Override public String thanks() { return "Danke!"; } }
Is this considered bad practice? Should I just override getter methods or just skip something I don't know about? It would be nice if you would like to help.
(I'm just playing Java now and I think that choosing a language will be quite funny. If you have experience sharing (libraries, properties, ...?), Feel free to do it) :)
music source share