Improvements would be:
implement a constructor like
Base(String id)
and call it from yourMainRequest
class, so every subclass ofBase
must have anid
value.public Base(String id) { this.id = id; }
consider using
final
on theid
member variable inBase
class and remove thesetId
method. In most cases you don't really want to set an id twice, do you?private final String id;
make a constructor like
MainRequest(String id, String key, String name)
to set all things at once like:public MainRequest(String id, String key, String name) { super(id); this.key = key; this.name = name; }
- the use of an
abstract
class is fine, since you're implementing thegetId
method and having a constructor but not want to instantiate this base class at all. possible add
final
key word on thekey
andname
member, if you only want to set these variables once in the constructor (assuming that, because you already have no setter methods):private final String key; private final String name;
post working code in your question (see
te
=>private
)- put the question to https://codereview.stackexchange.com/ :)
Of course, some points depending on what you really want to do! But you didn't tell some details about your intention!