views:

512

answers:

3

Hi,

I like to write my code slim and sexy (on the performance and memory side), I am using Mootools and was wondering if I was using it the correct way, also you can help me by telling me how to test my code to find the answers I am looking for my self.

//First we create a class like so:

var FirstClass = new Class {(
   'someFunc': function() { /* do stuff */ }
})

//Now this class uses first class with "Implements"

var SecondClass = new Class ({
   'Implements': [FirstClass, SomeOtherClass, SomeOtherOtherClass],
   'iAlsoDoStuff': function() {/*do stuff */}
})

// finally the class that Extends second class
var ThirdClass = new Class ({
   'Extends': SecondClass,
   'takeOverTheWorld': function() {/*code to win lottery */}
})

How can I tell if every time secondclass is extended it doesnt make a new copy of the Implemented classes? The reason I am doing what I am doing above is to Extend SecondClass for every class that needs it - doing so statically, while the second class cannot extend more then one class thus I am using Implements.

A: 

Extends and Implements are very well tested by Mootools developers themselves. Infact the whole test suite they use is available on their site (sorry don't have the link handy). You don't need to be testing core functionality of the framework, its done for you (and done very well too).

I'd suggest having a good read up on what Extend and Implement do on the mootools docs, clientcide website, mootorial, etc.

How many objects are you creating by the way? If its not a huge number then memory etc. should not be a major issue even if it was creating the objects in a memory heavy manner. Could this be premature optimisation?

Pete Duncanson
I am not trying to test the functionallity, I am trying to understand what exactly I am doing..For me using a framework is great, but I still want to know what are the implications of my work. (btw, I am not questioning the implementation, just trying to understand it)There is no documentation or examples that exaplin how to use this kind of inheretence with the MooTools library the best.If I understood what exactly was happening (by looking at firebug or otherwise) I would be very happy with not trying to prematurely optimize memory. Also this could cause bugs for me later on.
Romansky
+2  A: 

The main difference between Extends and Implements is that Implement changes the class's prototype, while Extend creates a copy. This means that if you implement a change into a class all instances of that class will inherit that change instantly, while if you use Extend then all existing instances will remain the same.

this is a quote from the mootorial, check it out. http://mootorial.com/wiki/mootorial/02-class/#implement-vs.-extend

as for the testing - i would very much recommend you build some sample cases with ninja classes and putting them on to mooshell.net - then ask for some analytical advice or the mootools mail list on google, SO does not seem to get many hits from the mootools core team. ideally, you want to talk to somebody like aaron newton :)

Dimitar Christoff
I actually joined the mootools google group the other day but for some reason didnt think about asking this questions there.Thats what I'll do now than :)Thanks!
Romansky
A: 

I finally got my answer on the Mootools google group, thought I would update it here in case some one finds interest in it.

http://groups.google.com/group/mootools-users/browse%5Fthread/thread/5aec78813fa51cc1

Enjoy! Roman

Romansky