Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing MVP, how to create a view from another view, linked with the same model object
    primarykey
    data
    text
    <p><strong>Background</strong></p> <p>We use the Model-View-Presenter design pattern along with the abstract factory pattern and the "signal/slot" pattern in our application, to fullfill 2 main requirements </p> <ul> <li>Enhance testability (very lightweight GUI, every action can be simulated in unit tests)</li> <li>Make the "view" totally independant from the rest, so we can change the actual view implementation, without changing anything else</li> </ul> <p>In order to do so our code is divided in 4 layers :</p> <ul> <li>Core : which holds the model </li> <li>Presenter : which manages interactions between the view interfaces (see bellow) and the core</li> <li>View Interfaces : they define the signals and slots for a View, but not the implementation</li> <li>Views : the actual implementation of the views</li> </ul> <p>When the presenter creates or deals with views, it uses an abstract factory and only knows about the view interfaces. </p> <p>It does the signal/slot binding between views interfaces. It doesn't care about the actual implementation. In the "views" layer, we have a concrete factory which deals with implementations.</p> <p>The signal/slot mechanism is implemented using a custom framework built upon boost::function.</p> <p>Really, what we have is something like that : <a href="http://martinfowler.com/eaaDev/PassiveScreen.html" rel="nofollow">http://martinfowler.com/eaaDev/PassiveScreen.html</a></p> <p>Everything works fine. </p> <p><strong>The problem</strong></p> <p>However, there's a problem I don't know how to solve. </p> <p>Let's take for example a very simple drag and drop example.</p> <p>I have two ContainersViews (ContainerView1, ContainerView2). ContainerView1 has an ItemView1. I drag the ItemView1 from ContainerView1 to ContainerView2.</p> <p>ContainerView2 must create an ItemView2, of a different type, but which "points" to the same model object as ItemView1.</p> <p>So the ContainerView2 gets a callback called for the drop action with ItemView1 as a parameter. It calls ContainerPresenterB passing it ItemViewB</p> <p>In this case we are only dealing with views. In MVP-PV, views aren't supposed to know anything about the presenter nor the model, right ? </p> <p>How can I create the ItemView2 from the ItemView1, not knowing which model object is ItemView1 representing ?</p> <p>I thought about adding an "itemId" to every view, this id being the id of the core object the view represents.</p> <p>So in pseudo code, ContainerPresenter2 would do something like </p> <pre><code>itemView2=abstractWidgetFactory.createItemView2(); this.add(itemView2,itemView1.getCoreObjectId()) </code></pre> <p>I don't get too much into details. That just work. The problem I have here is that those itemIds are just like pointers. And pointers can be dangling. Imagine that by mistake, I delete itemView1, and this deletes coreObject1. The itemView2 will have a coreObjectId which represents an invalid coreObject.</p> <p>Isn't there a more elegant and "bulletproof" solution ? </p> <p>Even though I never did ObjectiveC or macOSX programming, I couldn't help but notice that our framework is very similar to Cocoa framework. How do they deal with this kind of problem ? Couldn't find more in-depth information about that on google. If someone could shed some light on this.</p> <p>I hope this question isn't too confusing ... </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.
 

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