起因
我们在3D程序框架的设计中,将对象类设计成了这样:
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 64 65 66 67
| class Element { protected _id: string; protected _name: string; protected _type: ElementType; protected _children: Array<Element>; protected _parent: Element; protected _states: Array<State>; protected _position: Vector3; protected _rotation: Vector3; protected _scale: Vector3; protected _object3D: Object3D;
isNull(): boolean;
addChild(child: Element): boolean;
isDirty(): boolean;
setDirty(dirty: boolean);
setNormal();
setEmphasis();
setBlur();
setSelected();
update();
beforeUpdate();
afterUpdate();
useState(state: string);
useStates();
clearStates();
tick(); }
|
这存在如下问题:Element类包含了3个类别的属性:
这样会导致理解上的问题,程序也不合理优雅。
因此我们计划这样调整:
将Element类拆分为Model和View2个类
Model只存放数据描述/业务属性
View只存放渲染属性
去掉3D空间的属性,需要的时候,直接从3D对象上取
DataManager中,增加缓冲Models和Views对象的Map
兜兜转转,最终我们还是回到了Model-View模式。这也是ECharts的模式。
不由得让我思考一个问题:这种模式,是不是可视化的最佳程序设计呢?
常用可视化图表库的数据与渲染设计
ECharts
以柱状图来分析。