Connecting properties with variables at runtime

Hi guys
I just cant wrap my head around a solid solution for this thing I am trying to do:
I have 2 types of objects
a) measuring devices (e.g. scale, temp etc.) and
b) measurable devices (kettle, weights etc.)

I need to be able to connect the output (in the form of a single float variable) of measurable devices with a measuring device. I know interfaces can help me (together with polymorphism) to assign a method at runtime, but I am not sure how a single variable can fit into that solution, I made an interface “IPluggable” and enforce a method called ProcessInput(float Input), but I get stuck there.

I don’t expect code, just a high level (possible) solution.

Any help always appreciated, thanks!

Two solutions.

You can keep going down the interface route. Interfaces allow you to specify properties as well, which can be used to link to a variables.

However using interfaces is brittle and requires a fair bit of boiler plate and maintenance.

A more flexible solution might be to use reflection. The RemoteField class from Trend.Me does a fair bit of the work already. It was originally built for an identical purpose, although it’s mutated into an editor tool.

https://bitbucket.org/BoredMormon/trend.me/overview

You could combine this with attributes as in this Unite presentation. That could give you a very flexible runtime setup.

Edit: I should probably put up a warning that reflection is not for the faint of heart. Treating variables as variables is a bit of the mind job the first time you encounter it. Kind of like the Dr Strange movie. But its a powerful technique once you can grasp it.

Thanks BM for the thorough explanation, I will definitely have a look at the 2 solutions you suggested!