1 Replies - 783 Views - Last Post: 01 November 2013 - 12:52 PM

#1 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Models and Views - How many views is too many?

Posted 31 October 2013 - 01:20 PM

Hi all

I'm currently writing a networked application, and I just wanted to bounce my ideas off you guys and make sure I'm not doing anything awful.

The interaction of my objects looks like this:

Posted Image

The client and server both have copies of the networking components (for communicating changes to each other) and the model (for storing the current state of the information). I am now at a stage where I want to store the model in a MySQL database so I am planning on adding SQLView objects.

I am having hesitations since this is now a third type of view in my system; I have read that software should have no more layers than is necessary. Alternatively, I am considering adding logic to the NetworkView along the lines of:

if this is the server:
    push the change to the database


What seems reasonable to you guys?


A further niggling doubt in my mind is that I have moved away from model objects being related via composition, and instead am using ids. By doing this I am hoping my model will work nicer with the database, and I am preventing situations where every single relation of an object needs to be loaded at the same time.

Posted Image

This raises questions about how model objects will be loaded in the first place, since they will need to be requested from the server. Furthermore, in the same way I have a MenuManager for the MenuViews and a NetworkManager for the NetworkViews, I will need to have a manager for the loose model objects.

In this case, I feel like perhaps I am writing "god" objects.


Apologies for the rambly post, I'm just looking for some reassurance that I'm making good decisions. Alternatively, this project is very young, so please tell me if I should rewrite everything.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Models and Views - How many views is too many?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4312
  • View blog
  • Posts: 12,090
  • Joined: 18-April 07

Re: Models and Views - How many views is too many?

Posted 01 November 2013 - 12:52 PM

If you are doing an MVC approach here, what you are missing is your controllers which are going to have your business logic in them, they are going to ask for the models, manipulate them and give them to a specific view. Keep in mind that you are probably going to have a much larger number of views than controllers and models. That is because you can look at the same model in multiple different ways. One view might look at the model as a list, another might look at it as a summary, one might look at it from an executive point of view while another might be a view better suited for the IT staff.

It is not unheard of to have 2 or 3 views looking at the same model (or more). Controllers will handle the proper manipulation of the model data before giving it to the view. Thus the view is only worried about presentation.

The beauty of this is that also you should be able to add and delete views on a whim. So even later if you find that you have too many views, no problem, you could axe it safely without much of a second thought. When creating a view you should ask yourself "Is this view unique and is it only presenting not manipulating data?" (Your if statement should not be pushing anything to db in a view) If the question is yes to both, then create the view. If you find out later you never needed it, then axe it.

As for your models, your models should reflect the relationships in your database. Map out the database and its relations, then build your models to match. You shouldn't be worrying about models when you are creating your database schema. You create the schema related to the problem. Solve the problem. Then build your models and then build your views.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1