1

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...

H H
  • 263,252
  • 30
  • 330
  • 514
fishhead
  • 5,829
  • 7
  • 32
  • 43
  • 3
    Could you show a code sample of what you have so far? – Juliet Aug 28 '10 at 17:07
  • @Juliet - there isn't any code – fishhead Aug 28 '10 at 17:16
  • But there should be. Either an excerpt from the real code or a simple mock-up. If you want people to put some effort in the answers, shouldn't you at least try to make the question as clear as possible? – H H Aug 28 '10 at 17:54

2 Answers2

2

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.

H H
  • 263,252
  • 30
  • 330
  • 514
0

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: 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.

Community
  • 1
  • 1
GrantJ
  • 8,162
  • 3
  • 52
  • 46
  • 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 Aug 28 '10 at 17:17