tags:

views:

53

answers:

2

I have a couple of generic lists with completely different types of data.

In my generic lists I have created methods to do all the processing that makes sense from that level - that is I have the member function perform a summary and return a value or set of values. One of my reasoning for basing this calculation in the generic list is that it made reading the code in my opinion easier to read and maintain...but that’s subjective I guess.

Anyways I am at a point that some of the data in list_A needs to be shared with the List in List_B and vice-versa and I am stuck as to what would be the proper way to do this. My first consideration was to give List_B the location of List_A and so on.

or...is there something that I have totally missed is there some pattern that I should be using.

Thanks for any direction you can provide.

EDIT: Perhaps a few more words.

concider that List_A is a list of time collections for various equipment, the list would contain values for events during the day like : amount of time producing (ProductionTime) product 'X' or amount of time that equip was down for an unscheduled event like a breakage or the amount of time that fred the operator spent in the washroom and so on.

Now concider that List_B was a container for a history of equipment components that had been repaired. In industry there are standard performance indicators like the mean time between failure(MTBF) and so on.

Anyways the definition for MTBF is ProductionTime / Sum of failures.

so...List_B is tasked with determing MTBF for equip_x and in order to do so it needs some information from List_A.

I have housed the calculation for MTBF as a member function in List_B but it still needs som info from List_A...

A: 

It sounds like you're looking for something like the "friend" keyword in C++. That is, you'd like one type to be able to access the protected and private members of another type. There's no easy way to do this in C# because the "friend" keyword does not exist. See this related question for more details: http://stackoverflow.com/questions/203616/why-does-c-not-provide-the-c-style-friend-keyword

Without the "friend" keyword, I think your best option is to define an Interface that provides the functionality you want each type to have and let each define that Interface.

GrantJ
It doesn't really sound to me like he's trying to share internals between two classes. But even if he were, C# provides several means to simulate "friend" classes. See InternalsVisibleToAttribute (http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx) and the **internal** access modifier itself, which allows sharing between types *in the same assembly*.
Kirk Woll
+2  A: 

List_B is tasked with determing MTBF for equip_x

And that is where you start to go wrong I think. List_B should be doing List things, ie storing stuff and producing it when asked.

Calculations should be done in another part of your code (another layer). And then it is just a matter of creating the appropriate Join between List_A and List_B.

Single Responsibility, Coherency and all that.

Henk Holterman