I start in Java, trying to write a party quest system for the game that I am writing now, and I have some questions that I would like to get an answer to. I already went around and asked other people, but they are not familiar in Java.
In the past, I tried to create a bunch of classes and access them using several get methods. I found it incredibly tiring to write and think that I can combine them in an abstract class / implemented class. So the code looked more like this ...
DynastyPQInterface pq = new CustomPQ // or ....
DynastyPQInterface pq = new OtherCustomPQ
Of course, this represented difficulties, such as the ability to use only implemented methods. This did not allow me to access exclusive class methods, which I might want to use later.
Ultimately, I want to be able to use one get method to return any of these derived classes, but at the same time retain the ability to simply use the get method universally to call the methods that they have, how to execute, create, complete , while allowing I specifically use their exclusive methods. Is there a way to do this, or is it impossible?
If this is not yet clear ...
The code I wrote now is a base class that extends to other classes in a way ...
DynastyPQ (base) -> methods include (run(), execute(), end())
CustomAPQ (inherited from DynastyPQ) -> (has exclusive methods like getPoints())
CustomBPQ (inherited from DynastyPQ) -> (has exclusive methods like revivePlayer())
I want to write a get method to get rid of a few. What I have now is ...
DynastyPQ dynastyPQ;
DynastyPQ getPQ() {
return dynastyPQ;
}
void setPQ(DynastyPQ pq) {
dynastyPQ = pq;
}
Doing this ...
DynastyPQ pq = new CarnivalPQ();
I can only use DynastyPQ methods, not Carnival methods.
, , - ?
tl; dr → get, , X; .