[Containment] Disallow composition in immutable objects

Disallow composition in objects which cannot be created, under
the rationale that creatable objects must also be immutable.
WTD-1098.
This commit is contained in:
Victor Woeltjen
2015-04-10 19:24:16 -07:00
parent a55f8e1ab5
commit 036722b275
4 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/*global define*/
define(
[],
function () {
"use strict";
/**
* Disallow composition changes to objects which are not mutable.
* @constructor
*/
function CompositionMutabilityPolicy() {
return {
/**
* Is the type identified by the candidate allowed to
* contain the type described by the context?
* @param {Type} candidate the type of domain object
*/
allow: function (candidate) {
// Equate creatability with mutability; that is, users
// can only modify objects of types they can create, and
// vice versa.
return candidate.hasFeature('creation');
}
};
}
return CompositionMutabilityPolicy;
}
);