AbtractObject
AbstractObject with Object State Supports and free
method provides.
The derived class should overwrite the initialize
and finalize
methods.
Changes
V2.1.x
- add the state-able ability to any class.
- decoupled the abstract-object completely.
- All parts can be used individually.
- stateable = require('abstract-object/ability')
- eventable = require('events-ex/eventable')
- refCountable = require('ref-object/ability')
V2.x
- separate eventable from AbstractObject
- separate eventable from RefObject too
- add the eventable function to eventable any class('abstract-object/eventable').
- use the eventable plugin(events-ex) to implement eventable object.
V1.x
- AbstractObject inherits from EventEmitter.
- RefObject inherits from AbstractObject
- AbstractError
State-able Ability(V2.1.x)
add the Object State Supports and free
method to your class directly.
stateable = require 'abstract-object/ability'
module.exports = class AbstractObject
stateable AbstractObject
Note: the eventable ability must be after the stateable. like this:
stateable = require 'abstract-object/ability'
eventable = require 'events-ex/ability'
class MyObject
stateable MyObject
eventable MyObject # MUST BE after stateable
AbstractObject
RefObject
RefObject has moved to ref-object
The RefObject
is derived from AbstractObject. and add the RefCount
and AddRef/Release
Supports.
- methods:
release()
/free()
: Decrements reference count for this instance.
If it is becoming less than 0, the object would be (self) destroyed.addRef()
: Increments the reference count for this instance
and returns the new reference count.
Usage:
AbstractObject = require('abstract-object')
inherits = require('inherits-ex')
createObject = AbstractObject.create
#or createObject = require('inherits-ex/lib/createObject')
class MyObject
inherits MyObject, AbstractObject
initialize: (@a, @b)->
@cache = {}
finalize: ->
@cache = null
myObj = createObject(MyObject, 1, 2)
# if you do not wanna use `AbstractObject.create`, you MUST remember this:
# even the constructor is empty, you should call the parent's constructor manually.
# myObj = new MyObject()
class MyObject
inherits MyObject, RefObject
constructor: ->
# must call super method here:
super
initialize: (@a,@b)->
@cache = {}
finalize: ->
@cache = null
the javascript:
var AbstractObject = require('abstract-object')
var RefObject = require('ref-object')
var inherits = require('inherits-ex')
var createObject = AbstractObject.create
var MyObject = function() {
MyObject.__super__.constructor.apply(this, arguments);
}
var MyObject = function(){}
inherits(MyObject, RefObject)
MyObject.prototype.initialize = function(a,b) {
this.a = a
this.b = b
this.cache = {}
}
MyObject.prototype.finalize = function() {
this.cache = null
}
var myObj = createObject(MyObject, 1, 2)
var myObj = new MyObject(1,2)
AbstractError Classes
It has moved to abstract-error.
Enhanced Inheritance Functions
Moved to inherits-ex.
Util Functions
Moved to util-ex.