View Full Version : MVC architeture

12 Jan 2012, 8:34 PM
Hello guys, this time i don't have any problem with code... :D
It's an question that i have about the way that i'm building my app...

I'm creating a complex app, which will have many grids, many windows, many treepanels ane etc... So, i have the great idea to create a parent controller which will handlle with all the user events, like doubl click on the grid, load data on window, send ajax request to the server, update grid, delete grid and all MVC stuff...

Actually my base controller does everything on the page and the parent controller just set the urls which it will have to work with, and the grid alias, form alias, etc... i would like to know if it an good technique... Actually it is really nice, but i'm just on the begin... Maybe someona has tryed to do it before, and had some troubles that could share with me, maybe another way to code it... If someone would like to see the controller, just ask me, that i will post it here...

Thank you guys!

13 Jan 2012, 8:00 AM
Personally... I don't like really huge classes whether it be a view, store, or controller. I split my apps up into features and have controllers based on them (namespacing also). Some features require multiple controllers, it all depends on your app.

13 Jan 2012, 8:10 AM
Your way seems nice... Could you give some example how i could implement features as you said?!

13 Jan 2012, 8:16 AM
All it is is features of your app... so say you have a mail program... one feature may be contacts, another may be composing mail, another may be mail list... those are all features and could have their own controller

13 Jan 2012, 8:52 AM
On my app actually i have a controller to each grid, each treepanel... when you said features, i thought on break the controller functions on many files, as example... A specific file to control the grid actions like click events, onther file, to take care of server requests, etc...

If i understood right what you call as feature, today i'm working like you said, which each part on the system has their own controller...

Well, actually i'm doing it, if i going to create a new grid to show tasks for example, unstead of create a controller with all click events and server requests, i just write this simple controller:

Ext.define('gconnect.controller.Financeiro.Categorias.CargosFuncoes', {
extend: 'Ext.helper.Abstract.DefaultGridController',
views: [


and inside Ext.helper.Abstract.DefaultGridController i have all the events related to the grid...
What i wanna to know is if i keep coding like this, i could have troubles on future...

13 Jan 2012, 9:04 AM
I stay away from abstract controllers.

13 Jan 2012, 9:06 AM
i'm afraid to ask why... T_T
Could you explain why not extend controllers?

13 Jan 2012, 9:39 AM
I see people have events fire multiple times but don't know why... I can see if you want to share code but I usually create a controller that has shared code in it. I think that makes it more manageable for application logic.

13 Jan 2012, 11:20 AM
Ok, as other people had trouble with this, i have a great chance to have it too... so, what i should do? Because my controller has 300 lines of code (+/-)... Each time that i need some new feature, there goes plus 300 lines of code, and going... How i could make it dynamic, to not hardcode everything?

Today, with the controller extending it is really great (as development productivity), how i could make it dynamic without extend it?

16 Feb 2012, 7:56 AM
Would be very interrested to have an answer to that ...

16 Feb 2012, 8:17 AM
The jury is still out on the best design for your application.

The unfortunate answer is that "it depends".

I try not to bind events in an abstract controller that interact with the DOM ("click", "blur", etc). I definitely do use abstract classes though, I have a base one for controllers, stores, models, etc. that add in some functionality.

For example, my base controller looks like this (you can have this) -

Note: All this class does is pack on some additional functionality that I want my controller's to be able to do. This is a completely legit, safe thing to do. I encourage it.

Ext.define('My.controller.Base', {
extend: 'Ext.app.Controller',

//Retrieves an instance of the top-level view
//If it has not been created yet than one is instantiated
//Also, overrides the .close() method on the view to
//null out the instance reference on the controller (very necessary)
getViewInstance: function () {
var self = this;

if(!this.viewInstance) {
if(this.views && this.views.length) {

var view = this.getView(this.views[0]);

this.viewInstance = view.create();

this.viewInstance.close = function () {
view.prototype.close.apply(this, arguments);
self.viewInstance = null;


return this.viewInstance;

//Parameters - Function...
queue: function () {
this.queueItems = Array.prototype.slice.call(arguments);

//Executes the next function in the queue
//If the function returns true then automatically
//move to the next function in the queue. Otherwise,
//the controller has to manually release the next item
release: function () {
var fn, items = this.queueItems;

if(items && items.length) {
fn = items.shift();

if(typeof fn === 'function') {
if(fn.apply(this, Array.prototype.slice.call(arguments)) === true) {
this.release.apply(this, Array.prototype.slice.call(arguments));

//Load a model into all forms owned by this controller's view
load: function (model) {
var forms = this.getViewInstance().query('form');

if(forms && forms.length) {
for(var i = 0, l = forms.length; i < l; i++) {