Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thank you all for the answers.</p> <p>jalexiou - I will look into KeyedCollection, thanks (sheesh, I really need to register so I can post comments).</p> <p>James, as I wrote, I do want to work with interfaces (if nothing else, it simplifies unit-testing). My problem is that to initialize the actual ResourceManager I would need to pass the ComponentManager, and to initialize the CM I would need to pass the RM. What you suggested is basically a two-phase initialization which I referred to as solution 2. I would prefer to avoid such two-phase initialization, but perhaps I'm being too religious here.</p> <p>Philip, I think that passing the Component to ReportNewItem would be exposing too much to the ResourceManager (since Component supports various operations that I would rather not be accesible to the ResourceManager).</p> <p>However, thinking about it again, I can take the following approach:</p> <pre><code>class ComponentManager { ... } class Component { private ComponentAccessorForResource m_accessor; private ResourceManager m_rm; Component(ResourceManager rm) { m_accessor = new ComponentAccessorForResource(this); m_rm = rm; } void DoStuff() { Item item = CreateItem(); ResourceManager.ReportNewItem(item.ID, m_accessor); } int GetMaxResource() { ... } } class ComponentAccessorForResource { private Component m_component; ComponentAccessorForResource(Component c) { m_component = c; } int GetMaxResource() { return m_component.GetMaxResource(); } } ResourceManager rm = new ResourceManager(); ComponentManager cm = new ComponentManager(rm); </code></pre> <p>This seems clean enough to me. Hope no one disagrees :)</p> <p>My original objection to passing the Component (or indeed something like the accessor I proposed here) was that I would have to re-provide them to the ResourceManager upon initialization, since the ResourceManager persistently stores the Items it has. But as it turns out I have to re-initialize it with the Items anyway, so it's not a problem.</p> <p>Thanks again for the good discussion!</p>
    singulars
    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.
    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