Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

May I use a single big model object instead of many models? #9

Open
suexcxine opened this issue Dec 21, 2018 · 2 comments
Open

May I use a single big model object instead of many models? #9

suexcxine opened this issue Dec 21, 2018 · 2 comments

Comments

@suexcxine
Copy link

Could a ProgramWidget bind two or more models?
My view may corresponds to many models, for example, teacher's model, student's model,

If only one model could be bound to a ProgramWidget, although we can send msg(by msgsToBus) to each other, but how can we access other model's fields?

I saw in the examples models and views are one-to-one, if we want to share business code with web code(for example AngularDart), and web client's view is different from mobile client's view(for example search view and detail view are merged into one page), reuse model code will be somehow cumbersome(although possible).

So, IMHO, another way to go would be using only one big model, and bind that model to a root widget(MaterialApp ? ), so that we could access model's fields and dispatch messages from everywhere.

@p69
Copy link
Owner

p69 commented Dec 22, 2018

Hi @suexcxine
First of all, the purpose of model in Dartea or Elm is composition of all necessary data for the view. You should put on the model everything that must be displayed. This means that relationship between model and view usually is one-to-one, but also can be one-to-many.

If by single big object model you mean one class with many fields for the whole application, then it is not a good idea. But you can use single model's composition. In that way you have root model and many sub-models. Each sub-model may or may not have one or more corresponding view functions.

If you have much different screen sizes (e.g. mobile-web) then UI probably would be very different and you don't want to share much UI code between them. You can still share yore domain models and services instead, and also try to split your UI models into smaller parts which can be shared.

Well, if I understood you correctly, then I don't see benefits from having ability to connect one view with many models. Please, write your thoughts on this if I missed something. Thanks.

@suexcxine
Copy link
Author

Thank you for your reply.

I want to reuse not only domain models and services, but the whole thing under UI layer.

single big object model as the whole model could decouple modle and view, so the UI layer could be anything including flutter. Also, if one view could bind two or more models, this goal is also achieved.

And, I think UI should only show data from model with styles to users, dispatch user events to model, and reflecting data changes in the model if needed, and nothing else. so the whole thing under UI layer could be reused.

This also means that some state in the view, such as which tab is now active, should not be included in the single model, because this tab may not exist in other platform, such as web platform.

And, you said:

relationship between model and view usually is one-to-one, but also can be one-to-many.

Could you write a simple example to show that one view could access two or more models' fields?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants