I'm developing a game, I will generate objects. I have create an interface called IObject which has the following properties:

String tag // Tag for the object
Vector3 position // Where the element is positioned
Mesh mesh // This is how the object looks like
Material material // The material from which the object is build
void draw() // Method which draw the object

Now I wonder which will be better design practice to create another interface which takes all the things associated with drawing (position, mesh, material and the draw method) or to leave it this way?


Definitely take the stuff that relates to drawing out. Something like Drawable or Sprite or anything which clarifies the specific intended purpose of the object would be better

Interfaces are useful because they establish a specific contract regarding what you expect an object to provide; they should only include as much functionality as they need to for a specific range of use cases. Remember, objects can implement multiple interfaces; you don't have to have one giant interface which defines everything you could ever need in all cases, because that will get bloated and harder to mock for testing purposes. Single responsibility is your friend!

Not the answer you're looking for? Browse other questions tagged or ask your own question.