How to avoid reusing identical implementation code with an interface?

前端 未结 2 599
日久生厌
日久生厌 2021-01-06 06:04

First of all, I apologize for \"yet another interface question\". I thought that this one might be worth asking, though, as it\'s kind of a strange issue. The project I\'m u

2条回答
  •  猫巷女王i
    2021-01-06 06:40

    I never liked using interfaces.
    What I would do is make another base class
    The first class will be the base class lets call it SpaceObject. All space objects have attributes mass,velocity,friction(if any), rotation. SpaceObject will also extend UIcomponent as we want this to be added to the display list eventually and having inherited methods for hit detection would be nice.
    It will also have methods that will handle movement and whatever else needed for space objects.
    Then anytime I want to make a new space object I would just extend the SpaceObject class.
    public class SpaceShip extends SpaceObject or
    public class Commet extends SpaceObject.
    These classes will inherit the SpaceObjects attributes plus have their own like how long the tail is or what weapon it has. They should be encapsulated to handle whatever relates to them

提交回复
热议问题