Need help with suggestions for a system
So basically in my java project I have a system that I built where I create entities. There is an abstract class called CustomEntity and this is the main class for entities. I want all my custom entities to extend off of this class, but now the problem is that all classes which extend off of it will inherit the single constructor from the CustomEntity class, this constructor takes an entity as a parameter. This is to fully initialize the entity. What I want to do is to be able to override certain methods from the CustomEntity class within the child classes which extend off of it, for example, a boolean method called
canSpawn() which will be called to determine if the custom entity can be spawned. I want to be able to call this method before actually spawning in the custom entity but I cannot do this as I would need to spawn in the entity to pass into the constructor and create the object to call it.
So my idea was to create a blank constructor in the CustomEntity class that is protected and then at the start of the program create a factory of each registered entity type via reflection access on the empty constructor and then use this to make the calls on the overriden methods within each extending class when needed. This would work perfect, but the only problem is that it gives me a no such method exception as reflection seems to not be able to find super class constructors. I don't want to have to create an empty constructor on every single class that extends CustomEntity as this is redundant. Is there any solution to this or am I approaching this the wrong way? Also if possible I would like to create the empty constructor as private/protected so it is not visible for use in the API aside from internally to create the factory. Also I cannot create dummy entities to pass into the classes.1 Reply
⌛ This post has been reserved for your question.
Hey @davidclue! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.