Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Friend classes and OOP Composition

Given class A, which contains sets of raw data, and class B, which contains a re-organized version (GUI ready) of that data I would like to make the raw data in A visible in B.

Clearly the raw data in class A is contained in private members. I would like to make that data visible in B though the use of something akin to the C++ friend classes method.

How can I approach this?

Thank you.

like image 348
Rire1979 Avatar asked Feb 01 '10 16:02

Rire1979


1 Answers

Strictly speaking, you can't define a specific class (or list of classes) that you can expose the data to. You can, however, use the internal access modifier instead of private, which makes the members available to any class in the same assembly.

That being said, you should strongly consider exposing these members through properties rather than fields (which is what I'm guessing you're planning on exposing). Doing this will allow the class to define exactly how that information can be exposed to other classes and what--if anything--should happen when another class changes the data.

like image 55
Adam Robinson Avatar answered Oct 14 '22 19:10

Adam Robinson