Note that there are some explanatory texts on larger screens.

plurals
  1. POSharing class member data between sub components
    primarykey
    data
    text
    <p>I have an aggregate 'main' class which contains some data which I wish to share. The main class also has other class members. I want to share the data with these other class members. What is the correct / neatest way to do this?</p> <hr> <p>The specific example I have is as follows. The main class is a .net Form. I have some controls (actually controls within controls) on the main form which need access to the shared data.</p> <pre><code>Main Form - DataX - DataY - Control1 -- Subcontrol1 - Control2 -- SubControl2 </code></pre> <p>SubControls 1 and 2 both wish to access DataX and DataY.</p> <p>The trouble is, I feel like better practice (to reduce coupling), would be that either subcontrols should not know about Main Form, or Main Form should not know about subcontrols - probably the former.</p> <p>For subcontrols not to know about Main Form, would probably mean Main Form passing references to both Controls 1 and 2, which in turn would pass the references on to SubControls 1 and 2. Lots of lines of code which just forward the references. If I later added DataZ and DataW, and Controls 3 and 4 and SubControls 3 and 4, I'd have to add lots more reference forwarding code.</p> <p>It seems simpler to me to give SubControls 1 and 2 member references to Main Form. That way, any sub control could just ask for MainForm.DataX or MainForm.DataY and if I ever added new data, I could just access it directly from the sub controls with no hassle. But it still involves setting the 'MainForm' member references every time I add a new Control or Subcontrol. And it gives me a gut feeling of 'wrong'.</p> <p>As you might be able to tell I'm not happy with either of my solutions. Is there a better way?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload