Is using interface default methods implementation (like we have in C#8) alongside the component based architecture can be considered best practice?
For example suppose we define:
interface Walkable
{
int PositionX {get; set;}
int PositionY {get; set;}
void Move(Direction d)
{
// some logic
}
}
class Player : Walkable
{
// ...
}
We can easily add the walking functionality to more game objects (e.g NPCs) without duplicating code on one hand, and add more behavioral components to the Player (like Attackable for instance) on the other hand.
Aucun commentaire:
Enregistrer un commentaire