/
i_component.js
63 lines (57 loc) · 2.74 KB
/
i_component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//==============================================================
// i_component.js
// 'IComponent' interface class
// Design Pattern: Composite ('Component' participant)
// Other participant: 'Composite' (see IComposite in i_composite.js)
// 'Leaf' (see ILeaf in i_leaf.js)
// Purpose: allows you to compose objects into tree structures
// to represent whole-part hierarchies. Composite lets
// clients treat individual objects and composition
// of objects uniformly
// Pattern Subgroup: Structural
// Reference: http://ima.udg.edu/~sellares/EINF-ES1/CompositeToni.pdf
// Project: 'design-patterns-api' npm package
//==============================================================
'use strict';
/*jshint node: true*/
/*jshint esversion: 6*/
const MxI = require('mixin-interface-api/src/mixin_interface_api.js').MxI;
const ICoreComponent = require('./i_core_component.js').ICoreComponent;
//==================== 'IComponent' interface class ====================
class IComponent extends MxI.$Interface(ICoreComponent) {
// ---- 'getId()' service ----
// Constraint: OPTIONAL IMPLEMENTATION
// This service MAY be overridden by the implementation class
// Note: Inherited from 'IElement' (via IElement/IAction/ICoreComponent)
// ---- 'execute()' service ----
// Constraint: MANDATORY IMPLEMENTATION
// This service MUST be overridden by the implementation class
// Note: Inherited from 'ICoreComponent' (via IAction/ICoreComponent)
// ---- 'addChild()' service ----
// FALLBACK IMPLEMENTATION
// arg_child: an object which implements 'IComponent'
// Advice: return a 'child_id' (e.g. String, Integer, Uuid or Enumeration)
addChild(arg_child) {
MxI.$raiseNotImplementedError(IComponent, this);
} // IComponent.addChild()
// ---- 'removeChild()' service ----
// FALLBACK IMPLEMENTATION
// arg_child: an object which implements 'IComponent'
removeChild(arg_child) {
MxI.$raiseNotImplementedError(IComponent, this);
} // IComponent.removeChild()
// ---- 'removeChildById()' service ----
// FALLBACK IMPLEMENTATION
// child_id: a key (e.g. String, Integer, Uuid or Enumeration)
removeChildById(child_id) {
MxI.$raiseNotImplementedError(IComponent, this);
} // IComponent.removeChild()
// ---- 'getChild()' service ----
// child_id: a key (e.g. String, Integer, Uuid or Enumeration)
// returns an object which implements 'IComponent'
getChild(child_id) {
MxI.$raiseNotImplementedError(IComponent, this);
} // IComponent.getChild()
} // 'IComponent' interface class
MxI.$setAsInterface(IComponent).$asChildOf(ICoreComponent);
exports.IComponent = IComponent;