This is as much an object-oriented programming question as it is an extJS question:
We are re-writing a LARGE application here at work. It was originally written in a tag-based scripting language and we are re-writing it with an object-oriented/ext approach. It's a huge project and I'm pretty new to true object-oriented programming. Our question, to be very general, is this: When is it a good idea to extend an ext class into a new class as opposed to just creating an instance with the provided overrides? Or, to phrase it another way, when is an instance of an object too specific to be extended into a subclass?
I'm not sure I'm phrasing the general question clearly, so I'll ask in a more specific way too:
I am writing a very small module that uses a tree to display a parts breakdown report. For this module, I am using an EXT TreeLoader object. I am overriding the createNode() method to display special icons for each tree node. My plan was to create a class file with and to extend TreeNode into a special subclass used specifically for this module. It would look something like this:
Code:
Ext.ns('Ext.ux.ConfigCompView');
Ext.ux.ConfigCompView.ConfigCompTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
dataUrl: 'config_data.js',
requestMethod: 'get',
//Override createNode to set asm and comp icons
createNode : function(attr){
if (attr.component) {
attr.iconCls = 'component';
}
else if (attr.assembly) {
attr.iconCls = 'assembly'
}
return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
}
});
I will also create separate class files for the layout I end up using and for any other components I use.
Other programmers in the group contend that this class is far too specific and will likely never be re-used anywhere else in our application. Therefore, I should have just created an instance of the TreeLoader object with an override for createNode provided in the constructor call. Their reasoning is that creating a new class file and including it in the module's main page adds a level of complexity and ambiguity to the code for no added benefit. It's true that this class is very specific since the iconCls property is being defined and the dataUrl is hard-coded.
So when is it a good idea to break the code up into class files and when is it a bad idea? I was under the impression that it is ALWAYS better to break your code up in this way, but I understand the point of my fellow programmers and I want to make sure we are all on the same page before we continue programming.
Thanks in advance for any help you can provide. As I said, we're all fairly new to object-oriented programming (in the sense that we have never written a large application in this way) and we would love any best practice advice the community can provide.