[C#] What is an appropriate pattern to apply here? via /r/learnprogramming


[C#] What is an appropriate pattern to apply here?

I have a series of classes, A through Z, which inherit from IComponent. IComponentHandler holds a reference to each of these, using a Guid to differentiate between unique entities — For this concept, an entity is merely an ID with an associated set of components, as described in Cowboy Programming – Evolve your Hierarchy

At the moment, I'm having components talk to one another by going through an overarching ComponentManager. Confused? This might help a little.

ComponentManager { // Error-Checking, "IfExists", and constructors left out. public IComponentHandler<T> GetHandler<T>() where T : IComponent public T GetComponent<T>(Guid entityID) where T : IComponent } 

An 'Entity' is meant to have any number of associated Components, and the lack of a component is distinctly different from having an empty component (0 != NULL)


Finally, my issue is this: I need components to not only be able to talk to one another, but to be able to Push functionality upon existing components, if they exist.

Lets create two IComponents and call them Health and Attributes. Health has a function, int GetBonusHitPoints() which pulls a property, Constitution, from Attributes, runs a calculation on it, and spits out what I need.

Now, lets throw in another IComponent, Species. This species happens to be a Vampire, which, among other things, should force GetBonusHitPoints() to pull Charisma from Attributes instead of Constitution.

…How can I make this happen?

(If I can be more descriptive somehow, please let me know.)

Submitted July 17, 2017 at 09:03PM by Xagon
via reddit http://ift.tt/2u3pm6f

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s