Please ignore language syntax, I want to discuss only OOPS here.
I m here to discuss with you guys about game model architecture one is using interface(not inherit),the other one is using composite
namespace Interface {
interface IPickable {
void OnPick();
void OnDrop();
}
interface IBurnable {
void Burn();
}
//many interface here like pickable/iburnable
//and here will implement many many interfaces
class Entity : IPickable, IBurnable {
public void Burn() { }
public void OnDrop() { }
public void OnPick() { }
}
}
this is using traditional interface,
namespace Composite {
abstract class ComponentBase {
}
class Pickable : ComponentBase {
public void OnPick() { }
public void OnDrop() { }
}
class Burnable : ComponentBase {
public void Burn() { }
}
//many components here like pickable
class Entity {
List<ComponentBase> comps;
public void AddComp<T>() where T : ComponentBase { }
public T QueryComp<T>() where T : ComponentBase { }
}
}
the second namespace is using composite
I only know there the difference between them is we can add/remove component at runtime with composition,but interface cannot.
so please help me are there any other differents between them?and the advantage and disadvantange of them?
sorry for my English.
Aucun commentaire:
Enregistrer un commentaire