PDA

View Full Version : Define Superclasses (Base Classes) for Controller and Models!?



mik3e
2 Feb 2012, 11:29 AM
Hi guys!

Is there a way to declare superclasses of controller and models? With views this works via the component save function, but I haven´t found a solution how to do this for models and controller.

What I want to do:

- Build a base class for the rest proxy I´m using to handle communication errors
- Nearly every model in my app has a field "deleted" and "active", so it would make sense to inherit all models from this baseclass
- I also would like to declare a base.List controller, which serves some functions I want to use in all my grid views (e.g. deleting selected records)...

I know how to do this "by hand", but that´s not so senseful since I try to develop my whole app only with the new Designer 2.0.

Maybe someone can give me a hint :)

Cheers,
Mike

aconran
2 Feb 2012, 2:07 PM
You can not currently subclass/link your controllers or models.

You also cannot currently duplicate your controllers or models.

Duplicate we could fix rather quickly. Linking/Subclassing would be a rather large feature request we could look at in the future.

mik3e
2 Feb 2012, 2:42 PM
Ok, I c - do you have another idea how to prevent declaring the same method over and over again in n controller? Inheritance is one of the biggest plus in OOP, so it would be nice to use it also in the Designer.

Because on one hand the designer is really great and I think it could also be used for big enterprise solutions (don´t thinking on collaboration yet), but on the other hand then it should also feature the real power of OOP in connection with MVC...

aconran
2 Feb 2012, 2:56 PM
I agree. We're working on it.

Probably the easiest way to get around it at this point is to compose rather than inherit.

Collaboration should work pretty well with the file format we're currently using.

mik3e
3 Feb 2012, 6:37 AM
Just to be sure not to misunderstand you (as I did in the other thread :):
You mean declaring the (same) method for each controller seperatelly? Or is there a chance to declare static methods (as workaround till inheritance is possible) which then can be used? Something like:
Ext.Helper.MyController::deleteRecord();

aconran
3 Feb 2012, 6:40 AM
Say you have a controller named Help and another one named Main. You wanted to invoke similar/the same functionality from each of these places. You could create a controller named Util and then re-use it within Help and Main.

Something along the lines of:


this.getController('util').invokeMyCommonMethod();

ssamayoa
3 Feb 2012, 12:28 PM
mmm....

I crafted a medium size MVC application using OOP approach in views, controllers and stores, I mean, a lot of inheritance to avoid duplicated code.

Now I'm starting with Designer and even if I can craft a view quickly that saved time will be used in copy/paste code pieces of code.

How long we will wait for inheritance support on Designer?

aconran
3 Feb 2012, 4:06 PM
Inheritance support for views is already here.

They are linked instances and were also included as part of Designer 1.x.

ssamayoa
3 Feb 2012, 5:56 PM
Thanks for remindme that, I tried to integrate Designer in my work flow but I wrote so much OOP code than I throwed away it and stay with hand crafted code.

Defenitely I have to figure out how to take advantage of the tool because when crafting code by hand you have a lot of freedom but normaly slower than tool's generated code.

Regards.

Phil.Strong
5 Feb 2012, 8:27 PM
All true,

Any and all suggestions are welcome for improving Designer

mik3e
6 Feb 2012, 2:46 AM
Good morning from europe guys,

I´m implementing Aron´s suggestion with static helper classes to do a workaround for controller inheritance. But then I have another problem:

I inherited the store class I used, to show confirmation messages if a dataset is saved (I´m implementing a REST service). The inheritance structure looked as follows:


- Ext.data.Store
- MyApp.base.Store.Base extends Ext.data.Store
- MyApp.store.Concrete extends MyApp.base.Store

And in the MyApp.base.Store.Base I had this listeners for example:

write: function(store,operation,eOpts) {
console.log(operation);
Ext.example.msg('OPERATION "'+operation.action+'" SUCCESSFUL ON PROXY ','The store has been successfully written to the proxy')
}

For sure I can add a static store helper class and then add the calls to every store - but is there maybe another way? Is it possible to add self defined classes directly to Designer 2.0 at the moment? (For example to copy them in a special directory?).

Sorry for so many questions in the morning, but I hope it will help improving the Designer :)

Ciao,
Michael

aconran
6 Feb 2012, 12:13 PM
For sure I can add a static store helper class and then add the calls to every store - but is there maybe another way?

For now this is probably the easiest way.



Is it possible to add self defined classes directly to Designer 2.0 at the moment? (For example to copy them in a special directory?).

One central point to Designer 2.0 is that your project is a "working" directory. This means that you can copy and put in any additional file assets that you would like in this directory. For example if you defined a custom library that you wanted to invoke from within the designer and put it in the lib/ directory you could place the files in there.

There is no easy mechanism for linking them into your .html files yet. For now you would have to make a copy of the designer.html, rename it to something and edit it outside of the designer.

Resource management and linking will be coming to the designer in the future.