第六章 动态属性与属性值管理
动态属性与属性值管理是 WSaiOS 智能对象构建工程中的基础实现环节。第五章已经建立了智能对象的结构定义机制,明确了对象类型、对象标识、属性、方法、状态和关系等结构组成。本章进一步研究属性定义如何在运行过程中被创建、调整和管理,属性值如何与对象实例关联,以及属性数据如何参与结构匹配、计算、判断和前台呈现。
在传统程序开发中,对象属性通常在程序类中预先声明。例如,一个设备类可能预先定义设备名称、型号、编号、运行状态等字段。当业务对象发生变化时,开发人员需要修改类定义、数据库表结构和相关程序。这种方式适用于属性范围相对稳定的业务系统,但对于需要根据不同需求动态构建智能个体的 WSaiOS 工程而言,固定属性结构会限制对象的动态扩展能力。
WSaiOS 的动态属性机制将属性定义与属性值分开管理。属性定义描述一个属性是什么、具有什么数据类型、适用什么对象、受到哪些约束;属性值则描述某一个具体对象在当前时刻具有怎样的属性内容。属性定义可以动态创建、修改、停用或删除,属性值则按照对象实例和属性定义进行组织。这样,系统不必为每一种智能对象预先编写固定的数据字段,而是通过动态结构定义和通用属性管理程序完成对象属性的组织与赋值。
本章的工程实现重点是建立一套独立于具体对象类型的动态属性管理机制,使属性定义、属性值、对象实例、属性关系和前台呈现之间形成明确的数据关系。
6.1 属性定义与属性类型
属性定义是动态属性管理的起点。系统在创建一个智能对象结构时,需要明确对象具有什么属性,但不应要求所有对象都遵循同一套固定字段。不同对象可以拥有不同数量、不同名称和不同数据类型的属性,同一种对象也可以根据实际应用需求扩展属性。
例如,工业设备对象可能包含设备编号、生产厂家、额定功率、工作温度、运行速度和安装位置等属性;机器人对象可能包含运动范围、负载能力、移动速度、传感器配置和执行能力等属性;无人机对象可能包含飞行高度、续航时间、飞行速度、载荷能力和定位状态等属性。这些属性不是所有智能对象必须具备的统一字段,而是根据对象结构定义动态建立的属性集合。
因此,WSaiOS 需要将属性本身作为独立的结构定义对象进行管理。
属性定义可以抽象为:
\[ P_j=(ID_j,N_j,T_j,U_j,C_j,D_j,V_j) \]
其中,\(ID_j\) 表示属性标识,\(N_j\) 表示属性名称,\(T_j\) 表示数据类型,\(U_j\) 表示单位或表达方式,\(C_j\) 表示属性约束,\(D_j\) 表示默认值,\(V_j\) 表示属性定义版本。
属性定义不直接保存某个具体智能对象的实际属性值,而是为属性值提供统一的解释依据。对象实例引用属性定义后,才能按照该定义完成属性赋值、读取、修改和验证。
在工程数据层面,可以采用 JSON 组织动态属性定义:
{
"property_id": "prop_001",
"structure_id": "structure_device",
"name": "额定功率",
"data_type": "decimal",
"unit": "kW",
"required": true,
"default_value": null,
"constraints": {
"min": 0,
"max": 500
},
"description": "设备正常设计条件下的额定功率",
"version": 1,
"status": "active"
}
上述定义表示,在设备结构中建立一个名为“额定功率”的动态属性,其数据类型为十进制数值,单位为 kW,并设置有效范围。这里的属性定义可以被多个设备实例共同引用,但每个设备实例的额定功率值可以不同。
属性类型是属性定义的重要组成部分。WSaiOS 不应把属性类型简单限制为数据库中的字符串和数字字段,而应从数据表达、计算方式和使用条件出发,建立能够支持动态结构运行的数据类型体系。
例如,字符串类型用于名称、编号和描述;整数类型用于数量、计数和离散数值;小数类型用于功率、温度、重量和测量数据;布尔类型用于开关、启用状态和条件判断;日期时间类型用于时间记录;数组类型用于多个同类数据;对象类型用于引用具有独立结构的对象;结构化数据类型用于表达包含多个属性的复合数据。
此外,还需要区分属性的数据类型与属性的业务含义。比如“温度”和“速度”都可能使用 decimal 类型,但二者的单位、取值范围、计算方式和适用条件并不相同。数据类型负责确定数据如何存储和处理,属性定义中的语义信息则负责确定数据代表什么。
属性类型可以采用统一的数据类型注册机制。通用属性管理程序根据类型标识调用相应的解析器和验证器,而不是在每个业务模块中重复编写属性处理逻辑。
class PropertyTypeRegistry
{
private $types = array();
public function register($type, $handler)
{
if (!is_string($type) || $type === '') {
throw new InvalidArgumentException(
'属性类型标识不能为空'
);
}
if (!is_array($handler)) {
throw new InvalidArgumentException(
'属性类型处理定义无效'
);
}
$this->types[$type] = $handler;
}
public function get($type)
{
if (!isset($this->types[$type])) {
throw new RuntimeException(
'未注册的属性类型:' . $type
);
}
return $this->types[$type];
}
public function exists($type)
{
return isset($this->types[$type]);
}
}
在实际工程中,类型处理定义还应包含数据解析、格式验证、范围验证、序列化和反序列化等处理入口。不同程序语言可以实现不同的类型处理器,但必须遵守统一的属性数据规范。
动态属性类型的扩展不应导致既有属性定义失效。新增类型时,需要检查其存储方式、数据转换规则、计算适用范围和前后台显示方式。对于已经存在属性值的类型调整,也不能直接修改类型标识后继续使用,而应先分析原数据与新类型之间的兼容关系。
6.2 动态属性的创建与删除
动态属性的创建是智能对象结构动态扩展的具体过程。创建属性时,系统首先确定属性所属的结构定义或对象实例,然后生成属性标识,建立属性定义,验证属性类型和约束条件,最后将属性定义保存到结构数据管理系统。
属性创建应当与对象实例中的属性赋值分离。创建一个“工作温度”属性,并不意味着所有设备实例已经获得了工作温度的具体数值。属性创建只是在结构层面增加一个可以被实例引用的属性定义,实际数值需要在实例赋值阶段建立。
属性创建过程可以表示为:
\[ P_{new}=CreateProperty(D,A) \]
其中,\(D\) 表示所属结构定义,\(A\) 表示属性创建参数,\(P_{new}\) 表示生成的属性定义。
创建程序需要验证所属结构是否存在、属性标识是否重复、属性名称是否符合定义规范、数据类型是否已经注册,以及属性约束是否有效。
动态属性创建的程序流程如下:
#chatgpt-mermaid-_r_4m2_{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;fill:rgb(13, 13, 13);}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#chatgpt-mermaid-_r_4m2_ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_4m2_ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_4m2_ .error-icon{fill:rgb(243, 243, 243);}#chatgpt-mermaid-_r_4m2_ .error-text{fill:rgb(13, 13, 13);stroke:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4m2_ .edge-thickness-normal{stroke-width:1px;}#chatgpt-mermaid-_r_4m2_ .edge-thickness-thick{stroke-width:3.5px;}#chatgpt-mermaid-_r_4m2_ .edge-pattern-solid{stroke-dasharray:0;}#chatgpt-mermaid-_r_4m2_ .edge-thickness-invisible{stroke-width:0;fill:none;}#chatgpt-mermaid-_r_4m2_ .edge-pattern-dashed{stroke-dasharray:3;}#chatgpt-mermaid-_r_4m2_ .edge-pattern-dotted{stroke-dasharray:2;}#chatgpt-mermaid-_r_4m2_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4m2_ .marker.cross{stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4m2_ svg{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;}#chatgpt-mermaid-_r_4m2_ p{margin:0;}#chatgpt-mermaid-_r_4m2_ .label{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4m2_ .cluster-label text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4m2_ .cluster-label span{color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4m2_ .cluster-label span p{background-color:transparent;}#chatgpt-mermaid-_r_4m2_ .label text,#chatgpt-mermaid-_r_4m2_ span{fill:rgb(13, 13, 13);color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4m2_ .node rect,#chatgpt-mermaid-_r_4m2_ .node circle,#chatgpt-mermaid-_r_4m2_ .node ellipse,#chatgpt-mermaid-_r_4m2_ .node polygon,#chatgpt-mermaid-_r_4m2_ .node path{fill:rgb(222, 234, 251);stroke:rgb(83, 154, 248);stroke-width:1px;}#chatgpt-mermaid-_r_4m2_ .rough-node .label text,#chatgpt-mermaid-_r_4m2_ .node .label text,#chatgpt-mermaid-_r_4m2_ .image-shape .label,#chatgpt-mermaid-_r_4m2_ .icon-shape .label{text-anchor:middle;}#chatgpt-mermaid-_r_4m2_ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#chatgpt-mermaid-_r_4m2_ .rough-node .label,#chatgpt-mermaid-_r_4m2_ .node .label,#chatgpt-mermaid-_r_4m2_ .image-shape .label,#chatgpt-mermaid-_r_4m2_ .icon-shape .label{text-align:center;}#chatgpt-mermaid-_r_4m2_ .node.clickable{cursor:pointer;}#chatgpt-mermaid-_r_4m2_ .root .anchor path{fill:rgb(143, 143, 143)!important;stroke-width:0;stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4m2_ .arrowheadPath{fill:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4m2_ .edgePath .path{stroke:rgb(143, 143, 143);stroke-width:1px;}#chatgpt-mermaid-_r_4m2_ .flowchart-link{stroke:rgb(143, 143, 143);fill:none;}#chatgpt-mermaid-_r_4m2_ .edgeLabel{background-color:rgb(252, 252, 252);text-align:center;}#chatgpt-mermaid-_r_4m2_ .edgeLabel p{background-color:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4m2_ .edgeLabel rect{opacity:0.5;background-color:rgb(252, 252, 252);fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4m2_ .labelBkg{background-color:rgba(252, 252, 252, 0.5);}#chatgpt-mermaid-_r_4m2_ .cluster rect{fill:rgb(243, 243, 243);stroke:rgba(0, 0, 0, 0.1);stroke-width:1px;}#chatgpt-mermaid-_r_4m2_ .cluster text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4m2_ .cluster span{color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4m2_ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:12px;background:rgb(243, 243, 243);border:1px solid rgba(0, 0, 0, 0.1);border-radius:2px;pointer-events:none;z-index:100;}#chatgpt-mermaid-_r_4m2_ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4m2_ rect.text{fill:none;stroke-width:0;}#chatgpt-mermaid-_r_4m2_ .icon-shape,#chatgpt-mermaid-_r_4m2_ .image-shape{background-color:rgb(252, 252, 252);text-align:center;}#chatgpt-mermaid-_r_4m2_ .icon-shape p,#chatgpt-mermaid-_r_4m2_ .image-shape p{background-color:rgb(252, 252, 252);padding:2px;}#chatgpt-mermaid-_r_4m2_ .icon-shape .label rect,#chatgpt-mermaid-_r_4m2_ .image-shape .label rect{opacity:0.5;background-color:rgb(252, 252, 252);fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4m2_ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#chatgpt-mermaid-_r_4m2_ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#chatgpt-mermaid-_r_4m2_ .node .neo-node{stroke:rgb(83, 154, 248);}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].node rect,#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].cluster rect,#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].node polygon{stroke:url(#chatgpt-mermaid-_r_4m2_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].swimlane.cluster rect{filter:none;}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].node path{stroke:url(#chatgpt-mermaid-_r_4m2_-gradient);stroke-width:1px;}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].node .outer-path{filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].node .neo-line path{stroke:rgb(83, 154, 248);filter:none;}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].node circle{stroke:url(#chatgpt-mermaid-_r_4m2_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].node circle .state-start{fill:#000000;}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].icon-shape .icon{fill:url(#chatgpt-mermaid-_r_4m2_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4m2_ [data-look=”neo”].icon-shape .icon-neo path{stroke:url(#chatgpt-mermaid-_r_4m2_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4m2_ .node text{font-size:14px;font-weight:600;letter-spacing:normal;fill:rgb(0, 79, 153);}#chatgpt-mermaid-_r_4m2_ .edgeLabels text{font-size:13px;font-weight:600;letter-spacing:-0.08px;fill:rgb(0, 79, 153);}#chatgpt-mermaid-_r_4m2_ .node tspan[font-weight=”normal”],#chatgpt-mermaid-_r_4m2_ .edgeLabels tspan[font-weight=”normal”]{font-weight:600;}#chatgpt-mermaid-_r_4m2_ .edgeLabel .label rect{opacity:1;rx:13px;ry:13px;fill:rgb(245, 250, 255);stroke:rgb(206, 219, 229);stroke-width:1px;}#chatgpt-mermaid-_r_4m2_ .node rect,#chatgpt-mermaid-_r_4m2_ .node circle,#chatgpt-mermaid-_r_4m2_ .node ellipse,#chatgpt-mermaid-_r_4m2_ .node polygon,#chatgpt-mermaid-_r_4m2_ .node path{fill:rgb(229, 243, 255);stroke:rgba(0, 0, 0, 0.1);stroke-width:1px;}#chatgpt-mermaid-_r_4m2_ .node rect{rx:16px;ry:16px;}#chatgpt-mermaid-_r_4m2_ .mermaid-decision .label-container{fill:rgb(245, 250, 255);stroke:rgb(206, 219, 229);stroke-dasharray:2,2;}#chatgpt-mermaid-_r_4m2_ .edgePaths .flowchart-link{stroke:rgb(143, 143, 143);stroke-width:1px;stroke-linecap:round;stroke-linejoin:round;}#chatgpt-mermaid-_r_4m2_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4m2_ :root{–mermaid-font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;}提交属性创建参数读取所属结构定义检查结构权限与版本生成属性标识验证属性名称与数据类型验证属性约束定义是否合法返回错误信息保存属性定义生成结构新版本记录结构变更返回属性定义结果否是
属性创建程序可以通过独立服务实现:
class DynamicPropertyService
{
private $repository;
private $typeRegistry;
public function __construct(
$repository,
$typeRegistry
) {
$this->repository = $repository;
$this->typeRegistry = $typeRegistry;
}
public function create($structureId, $definition)
{
if (!$this->typeRegistry->exists(
$definition['data_type']
)) {
throw new RuntimeException(
'属性数据类型不存在'
);
}
if (empty($definition['name'])) {
throw new InvalidArgumentException(
'属性名称不能为空'
);
}
$definition['property_id'] =
$this->generatePropertyId();
$definition['structure_id'] = $structureId;
$definition['status'] = 'active';
$definition['version'] = 1;
$this->repository->saveDefinition(
$definition
);
return $definition;
}
private function generatePropertyId()
{
return 'prop_' . str_replace(
'.',
'',
uniqid('', true)
);
}
}
上述程序展示的是属性创建服务的职责划分。正式工程中,属性创建还应当放在数据库事务和结构版本管理机制之中,确保属性定义保存成功后,结构版本、变更记录和相关索引能够保持一致。
属性删除需要更加谨慎。动态属性可能已经被多个实例使用,也可能参与对象关系、计算条件、决策逻辑或前台页面映射。如果直接物理删除属性定义,就可能造成实例数据无法解释、程序引用失效和历史记录丢失。
因此,WSaiOS 应区分属性停用、逻辑删除和物理清理。
属性停用表示该属性暂时不参与新的赋值或运行处理,但原有数据仍然保留。逻辑删除表示属性不再属于当前有效结构定义,但历史结构版本和实例数据仍可以追溯。物理清理则属于数据维护操作,只有在确认不存在有效引用、历史保留要求和迁移依赖后才能执行。
删除操作可以表示为:
\[ Delete(P_j)= \begin{cases} Disable(P_j), & \text{存在有效引用}\\ Retire(P_j), & \text{存在历史数据}\\ Remove(P_j), & \text{确认无保留要求} \end{cases} \]
这里的判断并不是单纯依据属性值是否为空,而是需要检查属性与结构版本、对象实例、计算规则、方法参数和显示配置之间的依赖关系。
对于已经运行的智能个体,属性删除还应执行实例影响分析。若属性被某个运行方法引用,删除之前必须先处理该方法的参数定义或执行条件;若属性参与某项计算,则必须调整相应计算结构并重新验证。不能因为后台已经删除属性,就假定运行中的对象不再使用它。
6.3 属性值的数据组织
属性定义确定了属性的含义和数据规则,属性值则负责保存具体对象在实际运行中具有的属性内容。
WSaiOS 必须将属性定义与属性值分开存储。属性定义属于结构层,属性值属于实例数据层。同一个属性定义可以被多个实例引用,但不同实例拥有独立的属性值。
例如,三个设备实例可以共同引用“额定功率”属性定义,但分别保存 10.5 kW、22 kW 和 37 kW。系统通过属性定义解释这些数值,通过实例标识确定这些数值属于哪个设备。
因此,属性值不能简单地直接写入属性定义数据中。
属性值可以抽象为:
\[ V_{ij}=(I_i,P_j,X_{ij},T_{ij},Q_{ij}) \]
其中,\(I_i\) 表示对象实例标识,\(P_j\) 表示属性定义标识,\(X_{ij}\) 表示属性值,\(T_{ij}\) 表示值的记录时间,\(Q_{ij}\) 表示数据来源或质量状态。
这里的 \(i\) 表示对象实例,\(j\) 表示属性定义。通过实例标识和属性标识的组合,系统可以确定某一个实例的某一个属性值。
在数据库组织方面,可以采用属性定义表与属性值表分离的方式。
CREATE TABLE ws_property_definition (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
property_id VARCHAR(100) NOT NULL,
structure_id VARCHAR(100) NOT NULL,
property_name VARCHAR(200) NOT NULL,
data_type VARCHAR(50) NOT NULL,
unit VARCHAR(50) DEFAULT NULL,
required TINYINT(1) NOT NULL DEFAULT 0,
constraints_json JSON DEFAULT NULL,
default_value JSON DEFAULT NULL,
version INT NOT NULL DEFAULT 1,
status VARCHAR(20) NOT NULL DEFAULT 'active',
created_at DATETIME NOT NULL,
updated_at DATETIME DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_property_id (property_id),
KEY idx_structure_id (structure_id)
);
属性值表负责保存对象实例与属性定义之间的实际赋值关系:
CREATE TABLE ws_instance_property_value (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
instance_id VARCHAR(100) NOT NULL,
property_id VARCHAR(100) NOT NULL,
property_version INT NOT NULL,
value_json JSON DEFAULT NULL,
source_type VARCHAR(50) DEFAULT NULL,
source_reference VARCHAR(255) DEFAULT NULL,
quality_status VARCHAR(30) DEFAULT NULL,
recorded_at DATETIME NOT NULL,
updated_at DATETIME DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_instance_property (
instance_id,
property_id
),
KEY idx_property_id (property_id),
KEY idx_recorded_at (recorded_at)
);
这里采用 JSON 类型保存属性值,是为了支持不同属性类型的数据表达。对于需要高频计算、范围查询或统计分析的数值属性,工程上也可以增加经过验证的数值索引字段或专门的时序数据存储结构,而不必将所有数据都放在 JSON 中进行处理。
属性值还需要记录来源。属性值可能来自人工输入、设备传感器、外部数据接口、程序计算或其他智能对象。不同来源的数据可信程度和更新条件可能不同,因此不能只保存一个数值而不记录其来源。
例如,某设备的温度值可能来自传感器实时采集,也可能来自人工录入,还可能是程序根据其他数据计算得到。三种数据在使用时应当能够区分。尤其在自动控制场景中,计算得到的温度估计值不能未经验证就被当作传感器实际测量值。
对于需要持续变化的属性,还应区分当前值与历史值。当前值用于对象实时运行和状态判断,历史值用于变化分析、反馈和学习。若每次修改都覆盖原始值,将无法准确恢复对象过去的运行情况。
属性值的数据组织关系如下:
#chatgpt-mermaid-_r_4mo_{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;fill:rgb(13, 13, 13);}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#chatgpt-mermaid-_r_4mo_ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_4mo_ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_4mo_ .error-icon{fill:rgb(243, 243, 243);}#chatgpt-mermaid-_r_4mo_ .error-text{fill:rgb(13, 13, 13);stroke:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4mo_ .edge-thickness-normal{stroke-width:1px;}#chatgpt-mermaid-_r_4mo_ .edge-thickness-thick{stroke-width:3.5px;}#chatgpt-mermaid-_r_4mo_ .edge-pattern-solid{stroke-dasharray:0;}#chatgpt-mermaid-_r_4mo_ .edge-thickness-invisible{stroke-width:0;fill:none;}#chatgpt-mermaid-_r_4mo_ .edge-pattern-dashed{stroke-dasharray:3;}#chatgpt-mermaid-_r_4mo_ .edge-pattern-dotted{stroke-dasharray:2;}#chatgpt-mermaid-_r_4mo_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4mo_ .marker.cross{stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4mo_ svg{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;}#chatgpt-mermaid-_r_4mo_ p{margin:0;}#chatgpt-mermaid-_r_4mo_ .label{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4mo_ .cluster-label text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4mo_ .cluster-label span{color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4mo_ .cluster-label span p{background-color:transparent;}#chatgpt-mermaid-_r_4mo_ .label text,#chatgpt-mermaid-_r_4mo_ span{fill:rgb(13, 13, 13);color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4mo_ .node rect,#chatgpt-mermaid-_r_4mo_ .node circle,#chatgpt-mermaid-_r_4mo_ .node ellipse,#chatgpt-mermaid-_r_4mo_ .node polygon,#chatgpt-mermaid-_r_4mo_ .node path{fill:rgb(222, 234, 251);stroke:rgb(83, 154, 248);stroke-width:1px;}#chatgpt-mermaid-_r_4mo_ .rough-node .label text,#chatgpt-mermaid-_r_4mo_ .node .label text,#chatgpt-mermaid-_r_4mo_ .image-shape .label,#chatgpt-mermaid-_r_4mo_ .icon-shape .label{text-anchor:middle;}#chatgpt-mermaid-_r_4mo_ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#chatgpt-mermaid-_r_4mo_ .rough-node .label,#chatgpt-mermaid-_r_4mo_ .node .label,#chatgpt-mermaid-_r_4mo_ .image-shape .label,#chatgpt-mermaid-_r_4mo_ .icon-shape .label{text-align:center;}#chatgpt-mermaid-_r_4mo_ .node.clickable{cursor:pointer;}#chatgpt-mermaid-_r_4mo_ .root .anchor path{fill:rgb(143, 143, 143)!important;stroke-width:0;stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4mo_ .arrowheadPath{fill:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4mo_ .edgePath .path{stroke:rgb(143, 143, 143);stroke-width:1px;}#chatgpt-mermaid-_r_4mo_ .flowchart-link{stroke:rgb(143, 143, 143);fill:none;}#chatgpt-mermaid-_r_4mo_ .edgeLabel{background-color:rgb(252, 252, 252);text-align:center;}#chatgpt-mermaid-_r_4mo_ .edgeLabel p{background-color:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4mo_ .edgeLabel rect{opacity:0.5;background-color:rgb(252, 252, 252);fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4mo_ .labelBkg{background-color:rgba(252, 252, 252, 0.5);}#chatgpt-mermaid-_r_4mo_ .cluster rect{fill:rgb(243, 243, 243);stroke:rgba(0, 0, 0, 0.1);stroke-width:1px;}#chatgpt-mermaid-_r_4mo_ .cluster text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4mo_ .cluster span{color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4mo_ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:12px;background:rgb(243, 243, 243);border:1px solid rgba(0, 0, 0, 0.1);border-radius:2px;pointer-events:none;z-index:100;}#chatgpt-mermaid-_r_4mo_ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4mo_ rect.text{fill:none;stroke-width:0;}#chatgpt-mermaid-_r_4mo_ .icon-shape,#chatgpt-mermaid-_r_4mo_ .image-shape{background-color:rgb(252, 252, 252);text-align:center;}#chatgpt-mermaid-_r_4mo_ .icon-shape p,#chatgpt-mermaid-_r_4mo_ .image-shape p{background-color:rgb(252, 252, 252);padding:2px;}#chatgpt-mermaid-_r_4mo_ .icon-shape .label rect,#chatgpt-mermaid-_r_4mo_ .image-shape .label rect{opacity:0.5;background-color:rgb(252, 252, 252);fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4mo_ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#chatgpt-mermaid-_r_4mo_ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#chatgpt-mermaid-_r_4mo_ .node .neo-node{stroke:rgb(83, 154, 248);}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].node rect,#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].cluster rect,#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].node polygon{stroke:url(#chatgpt-mermaid-_r_4mo_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].swimlane.cluster rect{filter:none;}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].node path{stroke:url(#chatgpt-mermaid-_r_4mo_-gradient);stroke-width:1px;}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].node .outer-path{filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].node .neo-line path{stroke:rgb(83, 154, 248);filter:none;}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].node circle{stroke:url(#chatgpt-mermaid-_r_4mo_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].node circle .state-start{fill:#000000;}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].icon-shape .icon{fill:url(#chatgpt-mermaid-_r_4mo_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4mo_ [data-look=”neo”].icon-shape .icon-neo path{stroke:url(#chatgpt-mermaid-_r_4mo_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4mo_ .node text{font-size:14px;font-weight:600;letter-spacing:normal;fill:rgb(0, 79, 153);}#chatgpt-mermaid-_r_4mo_ .edgeLabels text{font-size:13px;font-weight:600;letter-spacing:-0.08px;fill:rgb(0, 79, 153);}#chatgpt-mermaid-_r_4mo_ .node tspan[font-weight=”normal”],#chatgpt-mermaid-_r_4mo_ .edgeLabels tspan[font-weight=”normal”]{font-weight:600;}#chatgpt-mermaid-_r_4mo_ .edgeLabel .label rect{opacity:1;rx:13px;ry:13px;fill:rgb(245, 250, 255);stroke:rgb(206, 219, 229);stroke-width:1px;}#chatgpt-mermaid-_r_4mo_ .node rect,#chatgpt-mermaid-_r_4mo_ .node circle,#chatgpt-mermaid-_r_4mo_ .node ellipse,#chatgpt-mermaid-_r_4mo_ .node polygon,#chatgpt-mermaid-_r_4mo_ .node path{fill:rgb(229, 243, 255);stroke:rgba(0, 0, 0, 0.1);stroke-width:1px;}#chatgpt-mermaid-_r_4mo_ .node rect{rx:16px;ry:16px;}#chatgpt-mermaid-_r_4mo_ .mermaid-decision .label-container{fill:rgb(245, 250, 255);stroke:rgb(206, 219, 229);stroke-dasharray:2,2;}#chatgpt-mermaid-_r_4mo_ .edgePaths .flowchart-link{stroke:rgb(143, 143, 143);stroke-width:1px;stroke-linecap:round;stroke-linejoin:round;}#chatgpt-mermaid-_r_4mo_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4mo_ :root{–mermaid-font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;}智能对象结构定义属性定义集合智能对象实例实例属性值集合属性标识实例标识与属性标识属性定义解析属性值解释与验证当前属性值历史属性值属性来源与质量记录
通过这种组织方式,结构定义可以保持相对稳定,而实例属性值能够按照实际运行情况持续变化。
6.4 对象属性赋值机制
对象属性赋值是将属性定义与具体对象实例连接起来的过程。属性定义说明某个对象可以具有哪些属性,赋值操作则确定某个对象当前实际具有的属性内容。
WSaiOS 的属性赋值不是简单地执行 PHP 对象中的 $object->name = $value,而是需要经过对象标识确认、属性定义读取、数据类型解析、属性约束验证、赋值保存和结果确认等处理过程。
赋值操作可以表示为:
\[ Assign(I_i,P_j,X)= \begin{cases} V_{ij}=X, & Validate(P_j,X)=True\\ Reject, & Validate(P_j,X)=False \end{cases} \]
其中,\(I_i\) 表示目标实例,\(P_j\) 表示目标属性,\(X\) 表示准备写入的值。只有属性定义存在、实例允许使用该属性且数据通过验证,系统才能建立有效的赋值记录。
例如,为一个工业设备实例赋予额定功率:
{
"instance_id": "device_001",
"property_id": "prop_001",
"value": 22.5,
"unit": "kW",
"source_type": "manual_input"
}
系统首先读取 device_001 对应的对象实例,再通过 prop_001 获取属性定义,检查该属性是否属于实例当前使用的结构版本,随后验证数值类型和约束范围。验证通过后,保存属性值及来源信息。
赋值程序可以按照服务层职责进行组织:
class InstancePropertyService
{
private $instanceRepository;
private $propertyRepository;
private $valueRepository;
private $validator;
public function __construct(
$instanceRepository,
$propertyRepository,
$valueRepository,
$validator
) {
$this->instanceRepository = $instanceRepository;
$this->propertyRepository = $propertyRepository;
$this->valueRepository = $valueRepository;
$this->validator = $validator;
}
public function assign(
$instanceId,
$propertyId,
$value,
$source = 'system'
) {
$instance = $this->instanceRepository
->findById($instanceId);
if (!$instance) {
throw new RuntimeException(
'目标对象实例不存在'
);
}
$property = $this->propertyRepository
->findById($propertyId);
if (!$property) {
throw new RuntimeException(
'属性定义不存在'
);
}
if ($property['status'] !== 'active') {
throw new RuntimeException(
'属性当前不可赋值'
);
}
if (!$this->validator->validate(
$property,
$value
)) {
throw new InvalidArgumentException(
'属性值不符合定义约束'
);
}
return $this->valueRepository->save(
$instanceId,
$propertyId,
$property['version'],
$value,
$source
);
}
}
正式工程中还需要处理实例结构版本与属性定义版本之间的关系。如果实例使用的是旧结构版本,而目标属性只存在于新版本中,就不能直接赋值。系统必须先判断该实例是否已经完成结构迁移,或者该属性是否被明确允许作为兼容扩展使用。
对于一次需要赋予多个属性的操作,可以将多个赋值组织成一个事务。若其中某个必需属性验证失败,系统应按照预先定义的事务策略决定整体回滚还是保留部分有效结果,不能出现数据库只保存了一半、但程序却返回全部成功的情况。
此外,属性赋值还应支持不同来源之间的优先级和更新规则。例如,设备传感器产生的实时数据可能需要覆盖上一条传感器数据,但不能无条件覆盖人工确认的设备型号;人工修改的配置参数也不应被普通运行反馈随意覆盖。这些规则应当由属性的数据来源策略和更新约束决定,而不是散落在各个业务程序中。
6.5 属性读取、修改与验证
属性读取是智能对象运行过程中最常见的数据访问操作。运行程序根据对象实例标识和属性标识获取属性值,再结合属性定义解释其数据类型、单位、语义和使用条件。
读取过程不能只返回一个未经解释的数据值。对于需要参与结构计算的属性,系统还需要确认其定义版本、当前有效性、来源和质量状态。
属性读取可以表示为:
\[ Read(I_i,P_j)=Interpret(D_{P_j},V_{ij}) \]
其中,\(D_{P_j}\) 表示属性定义,\(V_{ij}\) 表示对象实例对应的属性值。Interpret 表示依据属性定义解释属性值的过程。
例如,读取一个设备的额定功率时,系统不仅需要取得数值 22.5,还需要知道它代表额定功率,单位为 kW,数据来源为人工配置,并且符合当前结构定义的有效范围。
属性修改则是对已有属性值进行更新。修改时必须重新执行数据类型和约束验证,同时根据属性的来源和权限规则判断是否允许覆盖。
属性修改可以表示为:
\[ V_{ij}^{t+1}=Update(V_{ij}^{t},X) \]
但只有满足下列条件时,更新才有效:
\[ Valid(P_j,X)\land Authorized(I_i,P_j)\land AllowedSource(Q,X) \]
这里分别表示属性值符合定义约束、当前操作具备修改权限,以及数据来源符合属性更新规则。
属性验证应当分为多个层次。首先验证数据格式和类型,例如整数属性不能直接接受无法解析的文本。其次验证属性值范围,例如温度、功率和速度是否超出定义范围。再次验证语义约束,例如单位是否一致、对象是否允许使用该属性。最后还要验证运行条件,例如某个设备只有在特定状态下才允许修改某项运行参数。
对于涉及物理设备的属性,还必须区分配置值、指令值和反馈值。例如,将目标温度设置为 25℃,只能说明系统已经保存了目标温度配置,不能据此认定设备实际温度已经达到 25℃。实际温度必须通过设备反馈或其他可信测量来源确认。
属性验证程序可以采用独立验证器:
class PropertyValueValidator
{
public function validate($definition, $value)
{
$type = $definition['data_type'];
if ($type === 'integer') {
if (!is_int($value)) {
return false;
}
}
if ($type === 'decimal') {
if (!is_numeric($value)) {
return false;
}
}
if ($type === 'boolean') {
if (!is_bool($value)) {
return false;
}
}
if ($type === 'string') {
if (!is_string($value)) {
return false;
}
}
$constraints =
isset($definition['constraints'])
? $definition['constraints']
: array();
if (is_numeric($value)) {
if (
isset($constraints['min']) &&
$value < $constraints['min']
) {
return false;
}
if (
isset($constraints['max']) &&
$value > $constraints['max']
) {
return false;
}
}
return true;
}
}
上述示例只展示了基础类型与数值范围验证。正式类型验证器还需要支持数组、对象、日期时间、枚举、单位换算、嵌套结构、空值策略以及自定义约束。对于浮点数计算,还应考虑精度和单位转换问题,避免仅凭字符串或数值表面形式判断数据有效。
属性修改还应保留必要的变更记录。记录内容包括修改前的值、修改后的值、操作来源、修改时间、修改原因和验证结果。对于关键控制属性,还应记录执行授权和反馈确认信息,以便在运行异常时追溯数据变化过程。
6.6 属性之间的关联关系
动态属性不仅可以独立存在,还可以与同一对象中的其他属性建立关联。属性关联用于表达不同属性之间的依赖、约束、计算和条件关系,使属性值能够参与更复杂的结构计算。
例如,工业设备的额定功率、实际功率和负载率之间存在计算关系;机器人的目标位置、当前位置和运动误差之间存在计算关系;无人机的剩余电量、飞行速度和预计续航时间之间也可能存在计算关系。
这些关系不能仅通过属性名称推断,而应当在结构定义中明确表达。
属性关联可以抽象为:
\[ R_p=(ID,A,B,T,C,F) \]
其中,\(ID\) 表示关联标识,\(A\) 表示源属性,\(B\) 表示目标属性,\(T\) 表示关联类型,\(C\) 表示关联条件,\(F\) 表示计算或处理规则。
关联类型可以包括依赖关系、计算关系、约束关系、条件关系和同步关系等。不同类型的关联关系对应不同的执行方式。
例如,负载率可以通过实际功率与额定功率计算得到:
\[ L=\frac{P_a}{P_r}\times100\% \]
其中,\(L\) 表示负载率,\(P_a\) 表示实际功率,\(P_r\) 表示额定功率。当额定功率为零或数据无效时,该计算必须被拒绝,不能产生没有意义的结果。
属性关联定义可以使用动态数据表达:
{
"relation_id": "property_relation_001",
"relation_type": "calculation",
"source_properties": [
"actual_power",
"rated_power"
],
"target_property": "load_rate",
"method": "calculate_load_rate",
"conditions": {
"rated_power": {
"operator": ">",
"value": 0
}
},
"execution_policy": {
"trigger": "source_value_changed",
"validate_before_execute": true
}
}
这里定义的是属性之间的计算关系。实际计算方法由系统中经过注册和验证的程序实现,结构定义只负责描述使用哪些属性、产生什么结果以及满足什么条件时执行。
属性关联的执行过程可以表示为:
#chatgpt-mermaid-_r_4nl_{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;fill:rgb(13, 13, 13);}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#chatgpt-mermaid-_r_4nl_ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_4nl_ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_4nl_ .error-icon{fill:rgb(243, 243, 243);}#chatgpt-mermaid-_r_4nl_ .error-text{fill:rgb(13, 13, 13);stroke:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4nl_ .edge-thickness-normal{stroke-width:1px;}#chatgpt-mermaid-_r_4nl_ .edge-thickness-thick{stroke-width:3.5px;}#chatgpt-mermaid-_r_4nl_ .edge-pattern-solid{stroke-dasharray:0;}#chatgpt-mermaid-_r_4nl_ .edge-thickness-invisible{stroke-width:0;fill:none;}#chatgpt-mermaid-_r_4nl_ .edge-pattern-dashed{stroke-dasharray:3;}#chatgpt-mermaid-_r_4nl_ .edge-pattern-dotted{stroke-dasharray:2;}#chatgpt-mermaid-_r_4nl_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4nl_ .marker.cross{stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4nl_ svg{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;}#chatgpt-mermaid-_r_4nl_ p{margin:0;}#chatgpt-mermaid-_r_4nl_ .label{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4nl_ .cluster-label text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4nl_ .cluster-label span{color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4nl_ .cluster-label span p{background-color:transparent;}#chatgpt-mermaid-_r_4nl_ .label text,#chatgpt-mermaid-_r_4nl_ span{fill:rgb(13, 13, 13);color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4nl_ .node rect,#chatgpt-mermaid-_r_4nl_ .node circle,#chatgpt-mermaid-_r_4nl_ .node ellipse,#chatgpt-mermaid-_r_4nl_ .node polygon,#chatgpt-mermaid-_r_4nl_ .node path{fill:rgb(222, 234, 251);stroke:rgb(83, 154, 248);stroke-width:1px;}#chatgpt-mermaid-_r_4nl_ .rough-node .label text,#chatgpt-mermaid-_r_4nl_ .node .label text,#chatgpt-mermaid-_r_4nl_ .image-shape .label,#chatgpt-mermaid-_r_4nl_ .icon-shape .label{text-anchor:middle;}#chatgpt-mermaid-_r_4nl_ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#chatgpt-mermaid-_r_4nl_ .rough-node .label,#chatgpt-mermaid-_r_4nl_ .node .label,#chatgpt-mermaid-_r_4nl_ .image-shape .label,#chatgpt-mermaid-_r_4nl_ .icon-shape .label{text-align:center;}#chatgpt-mermaid-_r_4nl_ .node.clickable{cursor:pointer;}#chatgpt-mermaid-_r_4nl_ .root .anchor path{fill:rgb(143, 143, 143)!important;stroke-width:0;stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4nl_ .arrowheadPath{fill:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4nl_ .edgePath .path{stroke:rgb(143, 143, 143);stroke-width:1px;}#chatgpt-mermaid-_r_4nl_ .flowchart-link{stroke:rgb(143, 143, 143);fill:none;}#chatgpt-mermaid-_r_4nl_ .edgeLabel{background-color:rgb(252, 252, 252);text-align:center;}#chatgpt-mermaid-_r_4nl_ .edgeLabel p{background-color:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4nl_ .edgeLabel rect{opacity:0.5;background-color:rgb(252, 252, 252);fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4nl_ .labelBkg{background-color:rgba(252, 252, 252, 0.5);}#chatgpt-mermaid-_r_4nl_ .cluster rect{fill:rgb(243, 243, 243);stroke:rgba(0, 0, 0, 0.1);stroke-width:1px;}#chatgpt-mermaid-_r_4nl_ .cluster text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4nl_ .cluster span{color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4nl_ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:12px;background:rgb(243, 243, 243);border:1px solid rgba(0, 0, 0, 0.1);border-radius:2px;pointer-events:none;z-index:100;}#chatgpt-mermaid-_r_4nl_ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4nl_ rect.text{fill:none;stroke-width:0;}#chatgpt-mermaid-_r_4nl_ .icon-shape,#chatgpt-mermaid-_r_4nl_ .image-shape{background-color:rgb(252, 252, 252);text-align:center;}#chatgpt-mermaid-_r_4nl_ .icon-shape p,#chatgpt-mermaid-_r_4nl_ .image-shape p{background-color:rgb(252, 252, 252);padding:2px;}#chatgpt-mermaid-_r_4nl_ .icon-shape .label rect,#chatgpt-mermaid-_r_4nl_ .image-shape .label rect{opacity:0.5;background-color:rgb(252, 252, 252);fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4nl_ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#chatgpt-mermaid-_r_4nl_ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#chatgpt-mermaid-_r_4nl_ .node .neo-node{stroke:rgb(83, 154, 248);}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].node rect,#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].cluster rect,#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].node polygon{stroke:url(#chatgpt-mermaid-_r_4nl_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].swimlane.cluster rect{filter:none;}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].node path{stroke:url(#chatgpt-mermaid-_r_4nl_-gradient);stroke-width:1px;}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].node .outer-path{filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].node .neo-line path{stroke:rgb(83, 154, 248);filter:none;}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].node circle{stroke:url(#chatgpt-mermaid-_r_4nl_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].node circle .state-start{fill:#000000;}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].icon-shape .icon{fill:url(#chatgpt-mermaid-_r_4nl_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4nl_ [data-look=”neo”].icon-shape .icon-neo path{stroke:url(#chatgpt-mermaid-_r_4nl_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4nl_ .node text{font-size:14px;font-weight:600;letter-spacing:normal;fill:rgb(0, 79, 153);}#chatgpt-mermaid-_r_4nl_ .edgeLabels text{font-size:13px;font-weight:600;letter-spacing:-0.08px;fill:rgb(0, 79, 153);}#chatgpt-mermaid-_r_4nl_ .node tspan[font-weight=”normal”],#chatgpt-mermaid-_r_4nl_ .edgeLabels tspan[font-weight=”normal”]{font-weight:600;}#chatgpt-mermaid-_r_4nl_ .edgeLabel .label rect{opacity:1;rx:13px;ry:13px;fill:rgb(245, 250, 255);stroke:rgb(206, 219, 229);stroke-width:1px;}#chatgpt-mermaid-_r_4nl_ .node rect,#chatgpt-mermaid-_r_4nl_ .node circle,#chatgpt-mermaid-_r_4nl_ .node ellipse,#chatgpt-mermaid-_r_4nl_ .node polygon,#chatgpt-mermaid-_r_4nl_ .node path{fill:rgb(229, 243, 255);stroke:rgba(0, 0, 0, 0.1);stroke-width:1px;}#chatgpt-mermaid-_r_4nl_ .node rect{rx:16px;ry:16px;}#chatgpt-mermaid-_r_4nl_ .mermaid-decision .label-container{fill:rgb(245, 250, 255);stroke:rgb(206, 219, 229);stroke-dasharray:2,2;}#chatgpt-mermaid-_r_4nl_ .edgePaths .flowchart-link{stroke:rgb(143, 143, 143);stroke-width:1px;stroke-linecap:round;stroke-linejoin:round;}#chatgpt-mermaid-_r_4nl_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4nl_ :root{–mermaid-font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;}读取源属性值检查属性定义检查属性数据有效性读取属性关联定义验证关联条件条件是否满足记录未执行原因调用已注册计算方法生成目标属性值验证目标属性定义保存目标属性值记录计算来源与结果否是
属性关联关系还可能形成多层依赖。例如,某个计算属性依赖另外两个计算属性,而这两个计算属性又依赖原始采集数据。此时系统需要建立依赖关系图,确定计算顺序,检查是否存在循环依赖。
如果形成:
\[ P_1\rightarrow P_2\rightarrow P_3 \]
则可以按照依赖顺序执行。但如果形成:
\[ P_1\rightarrow P_2\rightarrow P_3\rightarrow P_1 \]
就需要检查是否属于有明确迭代规则的计算结构,还是错误的循环依赖。不能将所有循环关系都当作普通计算关系执行。
属性关联还需要考虑数据更新时间。若一个计算结果依赖两个不同时间采集的数据,系统应当检查时间差是否满足计算要求。对于实时控制场景,过期属性值可能导致错误判断。因此,属性关联除了检查数值本身,还应检查数据来源、有效时间和质量状态。
在 WSaiOS 中,属性关联是结构关系的一部分。属性关联结果可以继续参与对象状态判断、结构匹配、能力调用和决策计算,而不是停留在普通的数据字段处理层面。
6.7 动态属性与前台显示映射
动态属性最终需要进入实际应用界面,供用户查看、编辑和管理。由于不同智能对象具有不同的属性结构,前台页面不能依赖固定字段逐一编写。WSaiOS 需要建立动态属性与 Smarty 展示模板之间的数据映射机制,使前台页面能够根据对象当前的属性定义和属性值动态生成。
这里必须明确区分两个层次:动态属性定义属于智能结构系统,负责确定对象具有什么属性及其数据规则;Smarty 展示模板属于页面呈现系统,负责根据已经组织好的数据生成 HTML 页面。Smarty 不负责创建智能属性,不负责判断属性之间的智能关系,也不承担属性值的结构验证。
后台应当先读取对象实例的属性定义和属性值,再将其整理成统一的数据结构,最后赋值给 Smarty 模板。
动态属性显示数据可以组织为:
$displayProperties = array(
array(
'property_id' => 'prop_001',
'name' => '额定功率',
'data_type' => 'decimal',
'value' => 22.5,
'unit' => 'kW',
'editable' => true
),
array(
'property_id' => 'prop_002',
'name' => '设备编号',
'data_type' => 'string',
'value' => 'DEV-001',
'unit' => '',
'editable' => false
),
array(
'property_id' => 'prop_003',
'name' => '运行状态',
'data_type' => 'string',
'value' => '运行中',
'unit' => '',
'editable' => false
)
);
$smarty->assign(
'properties',
$displayProperties
);
Smarty 模板根据属性数据集合循环生成页面:
<div class="object-properties">
{foreach $properties as $property}
<div class="property-item"
data-property-id="{$property.property_id|escape}">
<span class="property-name">
{$property.name|escape}
</span>
<span class="property-value">
{$property.value|escape}
{$property.unit|escape}
</span>
</div>
{/foreach}
</div>
这种组织方式不要求为每一种智能对象单独编写一套属性展示页面。只要后台提供统一的属性数据集合,Smarty 就可以按照相同的呈现逻辑生成不同对象的属性区域。
但是,不同数据类型可能需要不同的显示控件。例如,字符串可以使用文本输入框,布尔值可以使用开关控件,数值可以使用数字输入框,枚举类型可以使用选择控件,对象类型则可以显示对象引用或关联对象信息。
因此,前台显示映射还需要根据属性类型选择合适的呈现方式。属性定义可以包含显示配置,但这些配置只决定页面如何呈现,不应改变属性的结构语义。
例如:
{
"property_id": "prop_001",
"display": {
"label": "额定功率",
"component": "number",
"show_unit": true,
"readonly": false,
"sort_order": 10
}
}
后台读取该配置后,将属性定义、当前属性值和显示配置组合为页面数据。Smarty 负责按照数据生成相应的 HTML 结构。
对于可编辑属性,前台提交的数据必须返回后台属性管理接口,由后台重新读取属性定义并执行验证。不能因为页面控件限制了输入范围,就认为数据一定合法。用户可以绕过前台页面直接提交请求,因此服务端验证必须始终存在。
前台修改属性的请求可以采用统一接口:
POST /api/instances/device_001/properties/prop_001
Content-Type: application/json
请求内容:
{
"value": 25.5,
"source_type": "user_input"
}
后台处理流程为:
#chatgpt-mermaid-_r_4ol_{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;fill:rgb(13, 13, 13);}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#chatgpt-mermaid-_r_4ol_ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_4ol_ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#chatgpt-mermaid-_r_4ol_ .error-icon{fill:rgb(243, 243, 243);}#chatgpt-mermaid-_r_4ol_ .error-text{fill:rgb(13, 13, 13);stroke:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4ol_ .edge-thickness-normal{stroke-width:1px;}#chatgpt-mermaid-_r_4ol_ .edge-thickness-thick{stroke-width:3.5px;}#chatgpt-mermaid-_r_4ol_ .edge-pattern-solid{stroke-dasharray:0;}#chatgpt-mermaid-_r_4ol_ .edge-thickness-invisible{stroke-width:0;fill:none;}#chatgpt-mermaid-_r_4ol_ .edge-pattern-dashed{stroke-dasharray:3;}#chatgpt-mermaid-_r_4ol_ .edge-pattern-dotted{stroke-dasharray:2;}#chatgpt-mermaid-_r_4ol_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4ol_ .marker.cross{stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4ol_ svg{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:16px;}#chatgpt-mermaid-_r_4ol_ p{margin:0;}#chatgpt-mermaid-_r_4ol_ .label{font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4ol_ .cluster-label text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4ol_ .cluster-label span{color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4ol_ .cluster-label span p{background-color:transparent;}#chatgpt-mermaid-_r_4ol_ .label text,#chatgpt-mermaid-_r_4ol_ span{fill:rgb(13, 13, 13);color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4ol_ .node rect,#chatgpt-mermaid-_r_4ol_ .node circle,#chatgpt-mermaid-_r_4ol_ .node ellipse,#chatgpt-mermaid-_r_4ol_ .node polygon,#chatgpt-mermaid-_r_4ol_ .node path{fill:rgb(222, 234, 251);stroke:rgb(83, 154, 248);stroke-width:1px;}#chatgpt-mermaid-_r_4ol_ .rough-node .label text,#chatgpt-mermaid-_r_4ol_ .node .label text,#chatgpt-mermaid-_r_4ol_ .image-shape .label,#chatgpt-mermaid-_r_4ol_ .icon-shape .label{text-anchor:middle;}#chatgpt-mermaid-_r_4ol_ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#chatgpt-mermaid-_r_4ol_ .rough-node .label,#chatgpt-mermaid-_r_4ol_ .node .label,#chatgpt-mermaid-_r_4ol_ .image-shape .label,#chatgpt-mermaid-_r_4ol_ .icon-shape .label{text-align:center;}#chatgpt-mermaid-_r_4ol_ .node.clickable{cursor:pointer;}#chatgpt-mermaid-_r_4ol_ .root .anchor path{fill:rgb(143, 143, 143)!important;stroke-width:0;stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4ol_ .arrowheadPath{fill:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4ol_ .edgePath .path{stroke:rgb(143, 143, 143);stroke-width:1px;}#chatgpt-mermaid-_r_4ol_ .flowchart-link{stroke:rgb(143, 143, 143);fill:none;}#chatgpt-mermaid-_r_4ol_ .edgeLabel{background-color:rgb(252, 252, 252);text-align:center;}#chatgpt-mermaid-_r_4ol_ .edgeLabel p{background-color:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4ol_ .edgeLabel rect{opacity:0.5;background-color:rgb(252, 252, 252);fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4ol_ .labelBkg{background-color:rgba(252, 252, 252, 0.5);}#chatgpt-mermaid-_r_4ol_ .cluster rect{fill:rgb(243, 243, 243);stroke:rgba(0, 0, 0, 0.1);stroke-width:1px;}#chatgpt-mermaid-_r_4ol_ .cluster text{fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4ol_ .cluster span{color:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4ol_ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;font-size:12px;background:rgb(243, 243, 243);border:1px solid rgba(0, 0, 0, 0.1);border-radius:2px;pointer-events:none;z-index:100;}#chatgpt-mermaid-_r_4ol_ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:rgb(13, 13, 13);}#chatgpt-mermaid-_r_4ol_ rect.text{fill:none;stroke-width:0;}#chatgpt-mermaid-_r_4ol_ .icon-shape,#chatgpt-mermaid-_r_4ol_ .image-shape{background-color:rgb(252, 252, 252);text-align:center;}#chatgpt-mermaid-_r_4ol_ .icon-shape p,#chatgpt-mermaid-_r_4ol_ .image-shape p{background-color:rgb(252, 252, 252);padding:2px;}#chatgpt-mermaid-_r_4ol_ .icon-shape .label rect,#chatgpt-mermaid-_r_4ol_ .image-shape .label rect{opacity:0.5;background-color:rgb(252, 252, 252);fill:rgb(252, 252, 252);}#chatgpt-mermaid-_r_4ol_ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#chatgpt-mermaid-_r_4ol_ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#chatgpt-mermaid-_r_4ol_ .node .neo-node{stroke:rgb(83, 154, 248);}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].node rect,#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].cluster rect,#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].node polygon{stroke:url(#chatgpt-mermaid-_r_4ol_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].swimlane.cluster rect{filter:none;}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].node path{stroke:url(#chatgpt-mermaid-_r_4ol_-gradient);stroke-width:1px;}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].node .outer-path{filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].node .neo-line path{stroke:rgb(83, 154, 248);filter:none;}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].node circle{stroke:url(#chatgpt-mermaid-_r_4ol_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].node circle .state-start{fill:#000000;}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].icon-shape .icon{fill:url(#chatgpt-mermaid-_r_4ol_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4ol_ [data-look=”neo”].icon-shape .icon-neo path{stroke:url(#chatgpt-mermaid-_r_4ol_-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#chatgpt-mermaid-_r_4ol_ .node text{font-size:14px;font-weight:600;letter-spacing:normal;fill:rgb(0, 79, 153);}#chatgpt-mermaid-_r_4ol_ .edgeLabels text{font-size:13px;font-weight:600;letter-spacing:-0.08px;fill:rgb(0, 79, 153);}#chatgpt-mermaid-_r_4ol_ .node tspan[font-weight=”normal”],#chatgpt-mermaid-_r_4ol_ .edgeLabels tspan[font-weight=”normal”]{font-weight:600;}#chatgpt-mermaid-_r_4ol_ .edgeLabel .label rect{opacity:1;rx:13px;ry:13px;fill:rgb(245, 250, 255);stroke:rgb(206, 219, 229);stroke-width:1px;}#chatgpt-mermaid-_r_4ol_ .node rect,#chatgpt-mermaid-_r_4ol_ .node circle,#chatgpt-mermaid-_r_4ol_ .node ellipse,#chatgpt-mermaid-_r_4ol_ .node polygon,#chatgpt-mermaid-_r_4ol_ .node path{fill:rgb(229, 243, 255);stroke:rgba(0, 0, 0, 0.1);stroke-width:1px;}#chatgpt-mermaid-_r_4ol_ .node rect{rx:16px;ry:16px;}#chatgpt-mermaid-_r_4ol_ .mermaid-decision .label-container{fill:rgb(245, 250, 255);stroke:rgb(206, 219, 229);stroke-dasharray:2,2;}#chatgpt-mermaid-_r_4ol_ .edgePaths .flowchart-link{stroke:rgb(143, 143, 143);stroke-width:1px;stroke-linecap:round;stroke-linejoin:round;}#chatgpt-mermaid-_r_4ol_ .marker{fill:rgb(143, 143, 143);stroke:rgb(143, 143, 143);}#chatgpt-mermaid-_r_4ol_ :root{–mermaid-font-family:-apple-system-body,ui-sans-serif,-apple-system,system-ui,”Segoe UI”,Helvetica,”Apple Color Emoji”,Arial,sans-serif,”Segoe UI Emoji”,”Segoe UI Symbol”;}前台提交属性修改验证用户身份与操作权限读取对象实例读取属性定义验证属性是否允许修改验证数据类型与约束验证是否通过返回错误信息保存属性值记录修改历史更新对象数据返回最新属性值前台刷新显示否是
这种机制使前台显示和后台属性管理形成完整的数据闭环。页面显示的数据来自对象实例,页面修改的数据必须经过结构定义验证,后台保存成功后再将实际结果返回前台。
对于工业控制、机器人和无人机等具有实际运行状态的对象,还应当将普通属性编辑与控制指令提交区分开来。用户在页面修改目标速度、目标位置或运行模式时,首先形成的是一个待处理的配置值或控制请求。该请求是否可以执行,需要进一步经过方法调用、运行条件和安全约束验证。页面显示的目标值不能直接替代设备实际反馈值。
因此,前台可以同时显示目标值、当前反馈值和执行状态,但这三类数据必须使用不同的属性定义或数据角色进行区分,避免将用户输入、控制指令和真实运行结果混为一谈。
本章工程实现总结
本章围绕 WSaiOS 智能对象的动态属性管理建立了从属性定义到实例赋值、从数据验证到关联计算、从后台管理到前台呈现的完整工程关系。
动态属性定义负责描述属性的标识、名称、数据类型、单位、约束和版本;属性值负责记录具体实例在特定时间具有的实际数据;属性赋值机制负责建立实例与属性定义之间的有效关联;属性读取和修改机制负责按照结构定义处理数据;属性关联机制负责使多个属性之间形成依赖、计算和条件关系;前台映射机制则将动态属性数据交给 Smarty 进行页面生成。
整个动态属性管理体系可以抽象为:
\[ \boxed{ P_D \rightarrow P_V \rightarrow Assign \rightarrow Validate \rightarrow Relation \rightarrow Display } \]
其中,\(P_D\) 表示属性定义,\(P_V\) 表示属性值,Assign 表示实例赋值,Validate 表示属性验证,Relation 表示属性关联处理,Display 表示前台显示映射。
从工程架构上看,动态属性管理需要保持几个明确的边界:属性定义不能与实例属性值混存;数据类型不能代替属性语义;属性值的保存不能代替实际设备执行结果;属性关联不能通过未经验证的程序调用实现;Smarty 页面呈现不能代替后台结构管理和数据验证。
通过上述机制,WSaiOS 可以在不为每种对象预先固定属性字段的情况下,按照不同智能个体的结构定义动态组织属性,并通过统一的属性管理程序完成数据赋值、读取、修改、验证和显示。
本章建立的是智能对象的动态属性数据基础。下一章将在此基础上研究动态方法与程序绑定机制,进一步解决智能对象如何定义方法、如何将结构中的方法定义映射到实际程序,以及如何在安全约束下调用程序实现对象能力的问题。