1

I am building a web application which is meant to help display prices of products. The web-app is centered around showing prices in a custom bar chart. I am thinking it should be composed of a Model View Controller architecture. I am looking for input on my design plan, there is more than one question here.

The model will hold the state and data retrieved from the server, as well as any state that is required to constrain the view. For example Say a certain window can only open if some toggle has been activated, the state of the toggle would be held in the model. I am thinking the state pattern would be useful here since it helps me model the system using state diagrams and there are likely to be many states. Also, it allows me to use class invariants to ensure the system is never put into an invalid state.

The view should be built upon the visitor pattern because all the elements on the screen are "Graphics", where the operations which act upon the graphics are independent of the graphics themselves. For example, all graphics can be scaled, positioned, hidden or shown. A rectangle shape might have a width and a height, but a function called "show" does not have anything to do with rectangles themselves. Does it make sense to define these operations myself when these operations are already available in JQuery? i.e I can scale an html element using $(element).css(width,numberOfPixels) ?

I think the controller should handle all the events from html elements as well as interacting with the server; like making server requests and handling the responses. Then, of course, having the controller manipulate the client side model. I've seen cases where people have implemented MVC frameworks, and they have the model communicating with the server, (rather than using the controller to communicate with the server). To me it makes more sense to use the controller to communicate with the server because the Model on the client side isn't meant for communicating, it's meant for holding state and logic. Why would I use the model to communicate with the server?

I've never used an MVC framework like AngularJS before, should I just use that rather than trying to implement my own MVC? Time is an issue, but I still want to be able to create a custom chart for the price chart.

1

I would keep separation of concerns in mind but also not overthink things. The view would be the graph. The model would be the data itself. The controller handles the interactions with the user interface and may have responsibility of loading the data into the view. A framework like angular helps to enforce this separation. If you choose angular note that not all graphing libraries play nicely with angular. Overall the model shouldn't communicate directly with the server but is basically the data retrieved from the server via the controller or another service used by the controller.

  • I made the mistake of starting with patterns first. I ended up using KnockoutJS and its component system. I am very much liking it. I can experiement with all sorts of patterns (I love its component system). – kiwicomb123 Aug 2 '18 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.