Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've seen 2 different approaches with MVC on the web.

One, like in ExtJS, is to bind the callbacks to the view via the controller. Finding every element on the view and adding the functionallity.

The other, like in angular.js and in the lift framework, is to bind in the views and just write the functionallity in the controller.

Which is better and cleaner?

The ExtJS approach has dumb views and all the logic in the controller which seems clean to me. I had problems with global IDs for GUI-elements or relative navigation to GUI-elements in this approach. When I changed the view, the controller couldn't find the buttons anymore or I had multiple instances of one button with the same ID on a single application, because of the global ID.

But I solved this with IDs that are only global in a view and can be on the application multiple times. So I could mess with the (dumb) views layout and design and the functionality wouldn't break.

The angular.js approach with the bindings in the view doesn't have the problem with global IDs. Also, the person who changes something in the view layout has to know the IDs anyway, so the controller can put the data at the right spot.

So if I write

<a ng-click="doThis()" />

for angular.js and implement doThis()

or

<a lid="buttonwhichdoesthis" />

for extjs and find the element with the local id and add doThis() as the handler on the controller side, it seems to not be so different.

The only thing is, the second one has one more layer of indirection, which seems cleaner.

The first one seems less effort.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

From my own point of view: neither of them is better the other one. They are just two different ways of achieving the same purpose.

I'm pretty use to work with different MVC frameworks based in Java as Spring MVC, JSF and GWT. The two former ones are as the angular.js you mentioned, they bind operations with the views and everything is executed on the server side (even UI rendering) whilst the latter, GWT, is JavaScript based and all the UI work is performed on the client side, then bound through means of callbacks to server-side calls to perform those other server-side tasks as data processing and so on.

I prefer to work with server-side frameworks and perform small AJAX calls from the UI to update specific parts of the application view. But I thing that's a personal preference.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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