Passing in and returning custom data - are interfaces the right approach?
|Added at||2017-01-05 14:01|
I'm writing code in a C# library to do clustering on a (two-dimensional) dataset - essentially breaking the data up into groups or clusters. To be useful, the library needs to take in "generic" or "custom" data, cluster it, and return the clustered data.
To do this, I need to assume that each datum in the dataset being passed in has a 2D vector associated with it (in my case
My first thought was to use generic types, and pass in two lists, one list of the generic data (i.e.
My next thought was to use inferfaces, where I define an interface
and ensure that the data that I pass in implements this interface (i.e. I can assume that each datum passed in has a
But this isn't really working out for me either. I'm using my C# library to cluster stops in a transit network (in a different project). The class is called
What I did then was inherit from
which as you can see implements the
This isn't really what I want, because I want to do things to the
I can still acheive what I want to, because e.g. I can retrieve the original objects by Id. But surely there is a much more elegant way to accomplish all of this? Is this the right way to be using interfaces? It seemed like such a simple idea - passing in and getting back custom data - but turned out to be so complicated.