I am writing a game. The question is simple and concerns fundamentals such as abstraction and, possibly, patterns.
There is an interface for an inactive object. That is, the object that is drawn can change the shape, size, position on the screen, etc. Here is its essence:
public interface IBasicObject { byte update(float dt); float getX(); float getY(); void setX(float pX); void setY(float pY); //... дальше идут другие графические геттеры и сеттеры } There is an object that implements this interface, called BasicObject. Such objects are used for decoration.
There is also the interface of a “living object”
public interface IHealthObject extends IBasicObject{ Body mBody = null; float GetHealth(); int GetTypeOfBlast(); Body GetBody(); void ResetBody(); void ReduceHealth(float healthToReduce1); void Kill(); } Well, there is a HealthObject object that implements this interface, and at the same time it is extended from the BasicObject class. It looks like this:
public class HealthObject extends BasicAnimatedObject implements IHealthObject That is, HealthObject not only has all the graphic components, but can also participate in collisions.
Now I have different classes (based on Array) to handle each type of object. How to create a class that can store any kind of object (either BasicObject or HealthObject). In this case, the appeal will be only to the functions specified in the most basic interface - to Update (dt) and getter-setters.
