bitpay/bitcore — pull request #114 by ryanxcharles (2014-03-06 02:14:44+00:00)
Title: remove classtool from Address, VersionedData, EncodedData

Classtool provides two particularly useful features: 1) allowing to overload dependencies in a class, 2) allowing a default instance of a class. However, it is unfriendly to new developers. One solution to this is to make classtool itself a little bit friendlier, as in @gasteve's soop. Another solution, explored here, is to remove classtool and rely on more traditional solutions to the same problems that do not require any dependencies at all.

In this PR I have removed classtool from Address, VersionedData, and EncodedData, which are all related classes. I have also updated the code to fix all tests. I have not removed classtool from other classes. The purpose of this PR is to demonstrate the feasibility of removing classtool and spark a discussion about removing classtool in the interests of making bitcore more friendly to new developers. This PR should not actually be pulled in unless we can all agree that removing classtool is the best option, and in that case the entire codebase should be updated to remove the classtool dependency.

For the record, here is an example of code that overloads dependencies of a class in a way that does not require classtool and is familiar to all javascript developers. The dependency being overloaded here is the database, which is replaced with a mockup database for the purpose of a test:

```
var sinon = require('sinon')
var assert = require('assert')

var Database = function() {
}

Database.prototype.query = function() {
return 'herp'
}

var Person = function() {
this.database = new Database()
}

Person.prototype.getName = function() {
return this.database.query()
}

it("returns the return value from the original function", function () {
var person = new Person()
var database = {};

database.query = function() {
return 'derp';
};
person.database = database;

assert.equal('derp', person.getName())
})

it("returns the return value from the original function", function () {
var person = new Person()
assert.equal('herp', person.getName())
})
```