1

Topic: Two models on one form

Hello! There is a certain form which displays a dial-up of the same entities in two types. These entities from the same table of a DB. But for convenience of operation the customer asked to represent them simultaneously on one form in the form of a tree and in the form of the table. In the table on the form there is a complete list of these entities. In a DB there is a table the parent-descendant for creation of a tree of these entities. The decision to make two models was accepted: one for tabular display, another for a tree. Not to be confused in models the class (ModelHolder) which incapsulates these models has been made and causes methods of update of both models at once. Here also there is a question, and where also who should cause methods of update of a DB? Complexity that actions over a tree can affect changes in the table, and on the contrary. It turns out that one model of changed, further it needs and to cause DB methods, and to change other model which in turn wants the same!  such recursion  from which I cannot be selected... When speech about one model then it is clear - it and pulls basis. And if speech about two parallel models I am lost. Like to pull a DB it would be possible from ModelHolder but then I cannot use these models in the same type in other places, after all they in that case will not be able to work with basis. One more decision - to make the general model both for a tree and for the table. Then all to become clearly. ModelHolder it is not necessary also we from the model we cause methods of a DB after model update. But besides, this model to turn out only for this form and it is more anywhere than it it will not be possible to use. And the separate model for the table and for a tree will be repeatedly used in the project. Prompt please how it is better to arrive here that then it was possible to reuse the code of these models? Thanks the Example with usage of the intermediate class which holds both models and cause update of the data in a DB: The pseudocode class ModelHolder {ModelTree _mtr = new ModelTree (); ModelTable _mtb = new ModelTable (); DataBaseWorker _dbw = new DataBaseWorker (); public void AddNewElement (object ob) {_mtr. AddNew (ob); _mtb. AddNew (ob); _dbw. AddNew (ob);}}

2

Re: Two models on one form

Hello, corpse56, you wrote: a C> Hello! The C> Is a certain form which displays a dial-up of the same entities in two types. These entities from the same table of a DB. But for convenience of operation the customer asked to represent them simultaneously on one form in the form of a tree and in the form of the table. In the table on the form there is a complete list of these entities. In a DB there is a table the parent-descendant for creation of a tree of these entities. The decision to make two models was accepted: one for tabular display, another for a tree. Here during this moment you and . What for to you two models? The model role just in that also consists to provide the coordinated data view in all . A C> One more decision - to make the general model both for a tree and for the table. Then all to become clearly. ModelHolder it is not necessary also we from the model we cause methods of a DB after model update. But besides, this model to turn out only for this form and it is more anywhere than it it will not be possible to use. It is not so clear, why it is it it will not be possible to use. The normal model should give enough information for  both a tree, and the table.

3

Re: Two models on one form

Hello, Sinclair, you wrote:  for the answer! S> here during this moment you and . What for to you two models? The model role just in that also consists to provide the coordinated data view in all . Well that on-separateness them to use in other places! S> it is not so clear, why it is it it will not be possible to use. The normal model should give enough information for  both a tree, and the table. But if such model to use we tell only for a tree on other form the remaining "tabular" part of this model is not becomes necessary! Here it also guards.

4

Re: Two models on one form

Hello, corpse56, you wrote: a C> Hello! The C> Is a certain form which displays a dial-up of the same entities in two types. These entities from the same table of a DB. But for convenience of operation the customer asked to represent them simultaneously on one form in the form of a tree and in the form of the table. In the table on the form there is a complete list of these entities. In a DB there is a table the parent-descendant for creation of a tree of these entities. The decision to make two models was accepted: one for tabular display, another for a tree. Not to be confused in models the class (ModelHolder) which incapsulates these models has been made and causes methods of update of both models at once. Here also there is a question, and where also who should cause methods of update of a DB? Complexity that actions over a tree can affect changes in the table, and on the contrary. It turns out that one model of changed, further it needs and to cause DB methods, and to change other model which in turn wants the same!  such recursion  from which I cannot be selected... When speech about one model then it is clear - it and pulls basis. And if speech about two parallel models I am lost. Like to pull a DB it would be possible from ModelHolder but then I cannot use these models in the same type in other places, after all they in that case will not be able to work with basis. One more decision - to make the general model both for a tree and for the table. Then all to become clearly. ModelHolder it is not necessary also we from the model we cause methods of a DB after model update. But besides, this model to turn out only for this form and it is more anywhere than it it will not be possible to use. And the separate model for the table and for a tree will be repeatedly used in the project. Prompt please how it is better to arrive here that then it was possible to reuse the code of these models? C thanks> the Example with usage of the intermediate class which holds both models and cause update of the data in a DB: a C> the C Pseudocode> a C> class ModelHolder a C> {a C> ModelTree _mtr = new ModelTree (); a C> ModelTable _mtb = new ModelTable (); a C> DataBaseWorker _dbw = new DataBaseWorker (); a C> public void AddNewElement (object ob) a C> {a C> _mtr. AddNew (ob); a C> _mtb. AddNew (ob); a C> _dbw. AddNew (ob); the C>}>} a C> Did a C similar with one model on wpf.

5

Re: Two models on one form

Hello, Qulac, you wrote: Q> Did similar with one model on wpf. Thanks for the answer! To you for certain, and even very much can be in the same project, the model separately for tabular representation was necessary. You were not jarred on by what it needed to be made anew, and the code there all repeats from "double model"?

6

Re: Two models on one form

Hello, corpse56, you wrote: a C> Hello, Qulac, you wrote: Q>> Did similar with one model on wpf. A C> Thanks for the answer! To you for certain, and even very much can be in the same project, the model separately for tabular representation was necessary. You were not jarred on by what it needed to be made anew, and the code there all repeats from "double model"? No, at me there that did not repeat, one object of model  to two types: to a tree and the table.

7

Re: Two models on one form

Hello, corpse56, you wrote: a C> Hello! The C> Is a certain form which displays a dial-up of the same entities in two types. These entities from the same table of a DB.... The decision to make two models was accepted... It seems To me somewhere here, to begin with, a terminology question. The model - it also is model is that logic which depends on display to the form a little. Under your requirements template MVP classically approaches: 1. We have one model which implements all sampling and data handling in terms BLL - DAL, 2.  knows as to work with model and to give the data view. 3 Two I twist fulfill one and  function, but I have different appearance (a tree and the table) - according to them it is possible to inherit from one interface (the program interface - ISomeView, not visual), implementing the necessary display. And then only to give  the necessary implementation. At certain implementation here still be finite the difference in data acquisition can. For example ModelTree can is lazy to take away the data at disclosure of subnodes, and ModelTable - to load all entirely, or it is page, or with virtualization - depends on data volume. But this problem can be bypassed if to make layer DAL or BLL it is is general-purpose enough implementing loading of the data with  and other. So the model should be one. , most likely too. And here I twist - as much as necessary.