第155章 ICAI面向对象工程
155.1 提出背景
第154章完成了机器个体形成,建立了:
IndividualInitialization→StructureFormation→CognitionFormation→BehaviorFormation→RuntimeFormationIndividualInitialization \rightarrow StructureFormation \rightarrow CognitionFormation \rightarrow BehaviorFormation \rightarrow RuntimeFormation
但是,理论上的机器个体仍然需要解决一个工程问题:
如何把一个具有身份、对象、属性、状态、关系、知识、目标、能力、方法、决策、行为、记忆和维护结构的机器个体,真正转换为可以在程序中运行的对象?
如果理论只停留在概念层:
IndividualIndividual
只是理论对象。
如果程序只是建立大量数组:
$individual = array();
则这些数据之间缺少稳定的对象边界、职责、方法和生命周期。
因此,ICAI需要建立:
ICAI理论→对象模型→面向对象模型→程序对象→Runtime对象\boxed{ ICAI理论 \rightarrow 对象模型 \rightarrow 面向对象模型 \rightarrow 程序对象 \rightarrow Runtime对象 }
本章建立ICAI面向对象工程(ICAI Object-Oriented Engineering)。
155.2 为什么使用面向对象
155.2.1 ICAI本身具有对象结构
ICAI所模拟的现实个体,本身就存在大量具有独立边界的对象。
例如一个企业个体:
EnterpriseEnterprise
内部可能存在:
CustomerCustomer ProductProduct OrderOrder EmployeeEmployee SupplierSupplier
这些对象具有:
- 身份;
- 类型;
- 属性;
- 状态;
- 关系;
- 历史;
- 行为。
因此:
RealityObject→CognitiveObject→ProgramObjectRealityObject \rightarrow CognitiveObject \rightarrow ProgramObject
天然适合采用面向对象工程。
155.3 面向对象不是为了模拟人类
ICAI采用面向对象,并不是因为面向对象“像人类思维”。
其工程原因是:
Object→State→Behavior→MethodObject \rightarrow State \rightarrow Behavior \rightarrow Method
具有明确的数据和操作边界。
程序对象可以把:
DataData
和:
OperationOperation
组织在一起。
因此:
Object=Data+State+MethodObject= Data+ State+ Method
但对于ICAI而言,还需要进一步加入:
Relation+History+BehaviorRelation+ History+ Behavior
形成:
ICAIObject=Identity+Data+State+Relation+Method+Behavior+History\boxed{ ICAIObject= Identity+ Data+ State+ Relation+ Method+ Behavior+ History }
155.4 面向对象解决什么问题
ICAI采用面向对象主要解决六类工程问题。
第一,对象边界
不同对象具有不同身份:
ObjectA≠ObjectBObject_A\neq Object_B
第二,状态管理
对象能够保存自己的当前状态:
Statet→Statet+1State_t\rightarrow State_{t+1}
第三,行为管理
对象可以拥有与自身职责相关的方法:
Object→MethodObject\rightarrow Method
第四,关系管理
对象可以与其他对象建立关系:
ObjectA→Relation→ObjectBObject_A\rightarrow Relation\rightarrow Object_B
第五,生命周期管理
对象能够经历:
Create→Update→Run→Change→ArchiveCreate \rightarrow Update \rightarrow Run \rightarrow Change \rightarrow Archive
第六,模块化
复杂机器个体可以分解为多个对象:
MachineIndividual=Object1+Object2+⋯+ObjectnMachineIndividual = Object_1+ Object_2+ \cdots+ Object_n
因此:
OOP→ObjectBoundary→Responsibility→State→Behavior→Runtime\boxed{ OOP \rightarrow ObjectBoundary \rightarrow Responsibility \rightarrow State \rightarrow Behavior \rightarrow Runtime }
155.5 理论对象与程序对象
这是ICAI面向对象工程最重要的区分之一。
155.5.1 理论对象
**理论对象(Theoretical Object)**是ICA I认知理论中用于描述现实实体、信息实体或认知实体的结构化对象。
例如:
O={ID,Type,Attribute,State,Relation,History}O= \{ ID, Type, Attribute, State, Relation, History \}
理论对象解决的是:
“机器系统如何描述这个对象?”
155.6 程序对象
**程序对象(Program Object)**是理论对象在程序运行环境中的具体实现实例。
例如:
class CognitiveObject
{
protected $id;
protected $type;
protected $attributes;
protected $state;
protected $relations;
protected $history;
}
程序对象解决的是:
“程序如何保存、读取、修改和运行这个对象?”
因此:
TheoreticalObject→ObjectModel→ProgramObjectTheoreticalObject \rightarrow ObjectModel \rightarrow ProgramObject
155.7 理论对象不等于程序对象
必须明确:
TheoreticalObject≠ProgramObjectTheoreticalObject\neq ProgramObject
理论对象属于理论模型。
程序对象属于软件运行环境。
二者之间存在映射:
ProgramObject=Implement(TheoreticalObject)ProgramObject=Implement(TheoreticalObject)
因此:
理论对象
↓
形式化定义
↓
对象模型
↓
PHP Class
↓
PHP Object
↓
Runtime Object
这就是ICAI从理论进入工程的基本路径。
155.8 一个理论对象如何成为程序对象
例如理论上定义:
CognitiveObject={ID,Type,Attribute,State,Relation}CognitiveObject= \{ ID, Type, Attribute, State, Relation \}
工程上建立:
class CognitiveObject
{
protected $id;
protected $type;
protected $attributes;
protected $state;
protected $relations;
}
程序运行时:
$object = new CognitiveObject();
此时:
Class→InstanceClass \rightarrow Instance
但是:
Class≠InstanceClass\neq Instance
其中:
- Class 是对象结构定义;
- Instance 是具体程序对象;
- Runtime Object 是当前运行中的对象实例。
155.9 ICAI的对象化原则
ICAI面向对象工程建立以下原则:
一个稳定理论实体→一个明确对象模型\boxed{ 一个稳定理论实体 \rightarrow 一个明确对象模型 } 一个对象模型→一个明确程序对象\boxed{ 一个对象模型 \rightarrow 一个明确程序对象 } 一个程序对象→明确的数据、状态和职责\boxed{ 一个程序对象 \rightarrow 明确的数据、状态和职责 }
因此:
Theory→Object→Class→InstanceTheory \rightarrow Object \rightarrow Class \rightarrow Instance
155.10 个体对象化
155.10.1 个体对象化定义
**个体对象化(Individual Objectification)**是指将ICAI中的“个体”定义为具有独立身份、类型、结构、状态和生命周期的程序对象,使一个机器个体能够在程序中作为独立对象存在。
理论模型:
Individual={ID,Type,Structure,State,History}Individual= \{ ID, Type, Structure, State, History \}
程序模型:
class MachineIndividual
{
protected $id;
protected $type;
protected $objects;
protected $attributes;
protected $states;
protected $relations;
protected $knowledge;
protected $goals;
protected $capabilities;
protected $methods;
protected $behaviors;
protected $memory;
protected $maintenance;
}
因此:
Individual→MachineIndividualIndividual \rightarrow MachineIndividual
155.11 个体不是一个简单数组
如果使用:
$individual = array(
'id' => 1,
'type' => 'enterprise'
);
虽然可以保存数据,但不能完整表达机器个体的对象职责。
ICAI要求:
Individual=Identity+Structure+Behavior+State+LifecycleIndividual = Identity+ Structure+ Behavior+ State+ Lifecycle
因此应建立:
class MachineIndividual
{
protected $id;
protected $type;
protected $state;
public function getId()
{
return $this->id;
}
public function getType()
{
return $this->type;
}
public function getState()
{
return $this->state;
}
}
程序对象由此具有明确边界。
155.12 个体对象的内部组成
机器个体对象可以组合多个领域对象:
MachineIndividual
│
├── Identity
├── Type
├── Objects
├── Attributes
├── States
├── Relations
├── Knowledge
├── Needs
├── Goals
├── Capabilities
├── Methods
├── Decisions
├── Behaviors
├── Actions
├── Results
├── Feedback
├── Memory
├── Experience
└── Maintenance
因此:
MachineIndividual=Composition(Object1,Object2,…,Objectn)MachineIndividual = Composition(Object_1,Object_2,\ldots,Object_n)
这是一种对象组合(Object Composition)。
155.13 个体对象与领域对象
机器个体不是把所有功能写在一个巨大Class中。
应当建立:
MachineIndividual→DomainObjectsMachineIndividual \rightarrow DomainObjects
例如:
MachineIndividual
↓
CognitiveObject
CognitiveState
CognitiveRelation
CognitiveKnowledge
CognitiveGoal
CognitiveCapability
CognitiveMethod
CognitiveDecision
CognitiveBehavior
CognitiveMemory
CognitiveMaintenance
因此:
Individual≠GodObjectIndividual \neq GodObject
机器个体是对象集合和对象关系的组织者,而不是所有计算都集中在一个Class中。
155.14 认知对象化
155.14.1 认知对象化定义
**认知对象化(Cognitive Objectification)**是指将对象、属性、状态、关系、场景、知识、需求、目标、能力等认知理论元素分别建立为具有明确结构和职责的程序对象。
核心:
Cognition→CognitiveObjectsCognition \rightarrow CognitiveObjects
例如:
Object→CognitiveObjectObject \rightarrow CognitiveObject Attribute→CognitiveAttributeAttribute \rightarrow CognitiveAttribute State→CognitiveStateState \rightarrow CognitiveState Relation→CognitiveRelationRelation \rightarrow CognitiveRelation Scene→CognitiveSceneScene \rightarrow CognitiveScene Knowledge→CognitiveKnowledgeKnowledge \rightarrow CognitiveKnowledge
155.15 对象对象化
理论:
O={ID,Type,Attribute,State,Relation,History}O= \{ ID, Type, Attribute, State, Relation, History \}
工程:
class CognitiveObject
{
protected $id;
protected $type;
protected $attributes;
protected $state;
protected $relations;
protected $history;
}
155.16 属性对象化
理论:
A={ID,ObjectID,Name,Type,Value,Unit,Source,Time}A= \{ ID, ObjectID, Name, Type, Value, Unit, Source, Time \}
工程:
class CognitiveAttribute
{
protected $id;
protected $objectId;
protected $name;
protected $type;
protected $value;
protected $unit;
protected $source;
protected $time;
}
属性对象负责描述对象的结构特征。
155.17 状态对象化
理论:
S={ObjectID,StateType,Value,Condition,Time}S= \{ ObjectID, StateType, Value, Condition, Time \}
工程:
class CognitiveState
{
protected $id;
protected $objectId;
protected $stateType;
protected $value;
protected $condition;
protected $time;
}
状态对象负责保存:
StatetState_t
以及状态变化:
Statet→Statet+1State_t\rightarrow State_{t+1}
155.18 关系对象化
理论:
R={Subject,Type,Object,Direction,Condition,State}R= \{ Subject, Type, Object, Direction, Condition, State \}
工程:
class CognitiveRelation
{
protected $id;
protected $subjectId;
protected $type;
protected $objectId;
protected $direction;
protected $condition;
protected $state;
}
关系本身也成为对象。
因此:
ObjectA→CognitiveRelation→ObjectBObject_A \rightarrow CognitiveRelation \rightarrow Object_B
155.19 场景对象化
场景由多个对象及其状态、关系和条件组成:
Scene={Object,Attribute,State,Relation,Condition,Event,Time,Space}Scene= \{ Object, Attribute, State, Relation, Condition, Event, Time, Space \}
工程:
class CognitiveScene
{
protected $id;
protected $objects;
protected $attributes;
protected $states;
protected $relations;
protected $conditions;
protected $events;
protected $time;
protected $space;
}
因此:
Scene=Composition(Object,Attribute,State,Relation)Scene = Composition( Object, Attribute, State, Relation )
155.20 知识对象化
理论:
Knowledge={ObjectKnowledge,StateKnowledge,RelationKnowledge,RuleKnowledge,MethodKnowledge,HistoryKnowledge}Knowledge= \{ ObjectKnowledge, StateKnowledge, RelationKnowledge, RuleKnowledge, MethodKnowledge, HistoryKnowledge \}
工程可以建立:
class IndividualKnowledge
{
protected $id;
protected $individualId;
protected $type;
protected $subject;
protected $object;
protected $content;
protected $condition;
protected $source;
protected $status;
}
知识对象负责保存结构化知识。
但:
Knowledge≠KnowledgeEngineKnowledge\neq KnowledgeEngine
知识对象负责保存知识结构。
知识引擎负责:
Read→Match→Combine→Judge→Derive→UpdateRead \rightarrow Match \rightarrow Combine \rightarrow Judge \rightarrow Derive \rightarrow Update
155.21 目标对象化
理论:
Goal=CurrentState→TargetStateGoal= CurrentState \rightarrow TargetState
工程:
class CognitiveGoal
{
protected $id;
protected $individualId;
protected $objectId;
protected $currentState;
protected $targetState;
protected $condition;
protected $priority;
protected $status;
protected $result;
}
目标对象保存目标本身。
目标计算则交给:
class GoalEngine
{
public function create($need)
{
return null;
}
public function evaluate($goal)
{
return null;
}
}
因此:
GoalObject≠GoalEngineGoalObject\neq GoalEngine
155.22 能力对象化
理论:
Capability=Ability+Object+Condition+State+RangeCapability= Ability+ Object+ Condition+ State+ Range
工程:
class CognitiveCapability
{
protected $id;
protected $individualId;
protected $type;
protected $object;
protected $condition;
protected $state;
protected $range;
protected $resource;
protected $method;
protected $result;
}
能力对象保存:
CapabilityCapability
能力引擎负责:
Capability→Availability→Matching→EvaluationCapability \rightarrow Availability \rightarrow Matching \rightarrow Evaluation
155.23 行为对象化
155.23.1 行为对象化定义
**行为对象化(Behavior Objectification)**是指将方法、决策、行为、动作、结果和反馈等动态行为结构分别转换为具有明确生命周期和运行职责的程序对象。
核心:
Behavior→BehaviorObjectBehavior \rightarrow BehaviorObject
完整行为链:
Method→Decision→Behavior→Action→Result→FeedbackMethod \rightarrow Decision \rightarrow Behavior \rightarrow Action \rightarrow Result \rightarrow Feedback
155.24 方法对象
class CognitiveMethod
{
protected $id;
protected $name;
protected $objectType;
protected $goalId;
protected $conditions;
protected $capabilities;
protected $steps;
protected $result;
protected $scope;
protected $status;
}
方法对象回答:
应该采用什么执行结构?
155.25 决策对象
class CognitiveDecision
{
protected $id;
protected $individualId;
protected $goalId;
protected $objectId;
protected $methodId;
protected $capability;
protected $condition;
protected $constraint;
protected $risk;
protected $action;
protected $expectedResult;
protected $status;
}
决策对象保存:
DecisionDecision
决策引擎负责:
Candidate→Evaluation→Selection→ConfirmationCandidate \rightarrow Evaluation \rightarrow Selection \rightarrow Confirmation
155.26 行为对象
class CognitiveBehavior
{
protected $id;
protected $individualId;
protected $objectId;
protected $goalId;
protected $methodId;
protected $decisionId;
protected $condition;
protected $actions;
protected $result;
protected $status;
}
行为对象负责管理:
BehaviorStateBehaviorState
以及:
Action1→Action2→⋯→ActionnAction_1\rightarrow Action_2\rightarrow\cdots\rightarrow Action_n
155.27 动作对象
class CognitiveAction
{
protected $id;
protected $subjectId;
protected $objectId;
protected $behaviorId;
protected $methodStep;
protected $condition;
protected $operation;
protected $input;
protected $output;
protected $result;
protected $state;
}
动作对象是行为执行中的具体操作单元。
因此:
Action⊂BehaviorAction\subset Behavior
155.28 结果对象
class CognitiveResult
{
protected $id;
protected $behaviorId;
protected $expected;
protected $actual;
protected $comparison;
protected $verification;
protected $status;
protected $createdAt;
}
结果对象保存:
ExpectedResultExpectedResult
与:
ActualResultActualResult
之间的关系:
ExpectedResult↔ActualResult→Comparison→VerificationExpectedResult \leftrightarrow ActualResult \rightarrow Comparison \rightarrow Verification
155.29 反馈对象
class CognitiveFeedback
{
protected $id;
protected $individualId;
protected $behaviorId;
protected $actionId;
protected $result;
protected $state;
protected $environment;
protected $evaluation;
protected $reason;
protected $createdAt;
}
反馈对象将行为结果重新连接到机器个体:
Feedback→Memory→Experience→Learning→UpdateFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update
155.30 维护对象化
维护结构同样需要对象化:
Maintenance=Risk+Protection+Conflict+Diagnosis+RepairMaintenance = Risk+ Protection+ Conflict+ Diagnosis+ Repair
对应:
MachineRisk
MachineProtection
MachineConflict
MachineDiagnosis
MachineRepair
例如:
class MachineRisk
{
protected $id;
protected $sourceObject;
protected $targetObject;
protected $condition;
protected $probability;
protected $impact;
protected $score;
protected $level;
}
以及:
class MachineRepair
{
protected $id;
protected $target;
protected $diagnosis;
protected $method;
protected $beforeState;
protected $expectedState;
protected $afterState;
protected $result;
protected $verification;
}
这样维护本身也成为机器个体内部的对象结构。
155.31 工程对象体系
ICAI最终需要建立一个统一对象体系。
ICAI
│
├── Individual Objects
│ ├── MachineIndividual
│ ├── IndividualIdentity
│ ├── IndividualType
│ └── IndividualBoundary
│
├── Cognitive Objects
│ ├── CognitiveObject
│ ├── CognitiveAttribute
│ ├── CognitiveState
│ ├── CognitiveRelation
│ ├── CognitiveScene
│ └── CognitiveKnowledge
│
├── Goal Objects
│ ├── CognitiveNeed
│ ├── CognitiveGoal
│ └── TargetState
│
├── Capability Objects
│ ├── CognitiveCapability
│ ├── CapabilityRequirement
│ └── CapabilityState
│
├── Method Objects
│ ├── CognitiveMethod
│ ├── MethodStep
│ └── MethodScope
│
├── Decision Objects
│ ├── CognitiveDecision
│ ├── DecisionCondition
│ ├── DecisionConstraint
│ └── DecisionResult
│
├── Behavior Objects
│ ├── CognitiveBehavior
│ ├── CognitiveAction
│ ├── CognitiveResult
│ └── CognitiveFeedback
│
├── Memory Objects
│ ├── MachineMemory
│ ├── MachineExperience
│ └── MachineHistory
│
├── Maintenance Objects
│ ├── MachineRisk
│ ├── MachineProtection
│ ├── MachineConflict
│ ├── MachineDiagnosis
│ └── MachineRepair
│
└── Runtime Objects
├── MachineIndividualRuntime
├── RuntimeContext
├── RuntimeState
└── RuntimeEvent
这就是:
ICAI Engineering Object System\boxed{ ICAI\ Engineering\ Object\ System }
155.32 对象与引擎的分工
ICAI工程不能把对象和计算引擎混在一起。
基本原则:
DomainObject→保存结构DomainObject \rightarrow 保存结构 Engine→执行计算Engine \rightarrow 执行计算
例如:
CognitiveObject
↓
ObjectEngine
↓
ObjectRecognition
↓
ObjectResult
再如:
CognitiveCapability
↓
CapabilityEngine
↓
CapabilityMatching
↓
CapabilityResult
因此:
Object≠EngineObject\neq Engine
155.33 对象、服务和Repository
进一步建立三层职责:
Domain Object
↓
Service / Engine
↓
Repository
例如:
CognitiveGoal→GoalEngine→GoalRepository→MySQLCognitiveGoal \rightarrow GoalEngine \rightarrow GoalRepository \rightarrow MySQL
其中:
Domain Object负责领域结构。
Engine / Service负责领域计算和业务流程。
Repository负责持久化。
因此:
Object→Engine→Repository\boxed{ Object \rightarrow Engine \rightarrow Repository }
155.34 完整MVC对象链
在PHP MVC工程中:
Controller→Service→Engine→DomainObject→Repository→MySQLController \rightarrow Service \rightarrow Engine \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL
例如机器个体运行:
Controller
↓
MachineIndividualRuntimeService
↓
MachineIndividualRuntimeEngine
↓
MachineIndividualRuntime
↓
CognitiveGoal
↓
CognitiveCapability
↓
CognitiveMethod
↓
CognitiveDecision
↓
CognitiveBehavior
↓
CognitiveAction
↓
CognitiveResult
↓
CognitiveFeedback
↓
Repository
↓
MySQL
这使理论对象、程序对象和数据库记录形成对应关系。
155.35 对象与MySQL映射
例如:
CognitiveObject↔cognitive_objectsCognitiveObject \leftrightarrow cognitive\_objects CognitiveAttribute↔cognitive_object_attributesCognitiveAttribute \leftrightarrow cognitive\_object\_attributes CognitiveState↔cognitive_object_statesCognitiveState \leftrightarrow cognitive\_object\_states CognitiveRelation↔cognitive_object_relationsCognitiveRelation \leftrightarrow cognitive\_object\_relations CognitiveGoal↔cognitive_goalsCognitiveGoal \leftrightarrow cognitive\_goals CognitiveCapability↔cognitive_capabilitiesCognitiveCapability \leftrightarrow cognitive\_capabilities CognitiveMethod↔cognitive_methodsCognitiveMethod \leftrightarrow cognitive\_methods CognitiveDecision↔cognitive_decisionsCognitiveDecision \leftrightarrow cognitive\_decisions CognitiveBehavior↔cognitive_behaviorsCognitiveBehavior \leftrightarrow cognitive\_behaviors CognitiveAction↔cognitive_actionsCognitiveAction \leftrightarrow cognitive\_actions CognitiveResult↔cognitive_resultsCognitiveResult \leftrightarrow cognitive\_results MachineMemory↔machine_memoriesMachineMemory \leftrightarrow machine\_memories
因此:
TheoryObject→PHPObject→Repository→MySQLRecord\boxed{ TheoryObject \rightarrow PHPObject \rightarrow Repository \rightarrow MySQLRecord }
155.36 对象生命周期
ICAI对象不是静态数据。
对象生命周期:
Create→Initialize→Active→Update→Change→ArchiveCreate \rightarrow Initialize \rightarrow Active \rightarrow Update \rightarrow Change \rightarrow Archive
对于Runtime对象:
Create→Ready→Running→Paused→Running→CompletedCreate \rightarrow Ready \rightarrow Running \rightarrow Paused \rightarrow Running \rightarrow Completed
异常情况下:
Running→Fault→Diagnosis→Repair→Verification→RunningRunning \rightarrow Fault \rightarrow Diagnosis \rightarrow Repair \rightarrow Verification \rightarrow Running
因此对象生命周期也是ICAI工程的一部分。
155.37 对象状态与对象行为
必须保持:
State≠BehaviorState\neq Behavior
状态描述:
对象现在是什么状态。
行为描述:
对象正在执行什么过程。
例如:
MachineState=RunningMachineState=Running
并不意味着:
Behavior=RunningBehavior=Running
正确关系是:
Object→StateObject \rightarrow State
而:
Decision→Behavior→ActionDecision \rightarrow Behavior \rightarrow Action
行为执行以后又可能改变状态:
Statet→ActionStatet+1State_t \xrightarrow{Action} State_{t+1}
155.38 对象关系与认知关系
程序对象之间的引用关系不能直接等同于认知关系。
例如:
$this->customer = $customer;
只是程序对象引用。
而:
Customer→PlacesOrder→OrderCustomer \rightarrow PlacesOrder \rightarrow Order
才是ICAI理论中的认知关系。
因此:
ProgramReference≠CognitiveRelationProgramReference\neq CognitiveRelation
程序引用负责软件对象组织。
认知关系负责机器个体对对象关系的表达。
二者可以建立映射:
CognitiveRelation→ProgramRelationCognitiveRelation \rightarrow ProgramRelation
但不能简单混为一谈。
155.39 对象化与机器个体形成
第154章的机器个体形成可以进一步转换成面向对象工程:
IndividualInitialization→IndividualObjectsIndividualInitialization \rightarrow IndividualObjects StructureFormation→ObjectCompositionStructureFormation \rightarrow ObjectComposition CognitionFormation→CognitiveObjectsCognitionFormation \rightarrow CognitiveObjects BehaviorFormation→BehaviorObjectsBehaviorFormation \rightarrow BehaviorObjects RuntimeFormation→RuntimeObjectsRuntimeFormation \rightarrow RuntimeObjects
最终:
Formation→ObjectComposition→RuntimeObject\boxed{ Formation \rightarrow ObjectComposition \rightarrow RuntimeObject }
155.40 ICAI面向对象工程总模型
建立统一模型:
Theory→FormalModel→DomainObject→Class→Instance→RuntimeObject\boxed{ Theory \rightarrow FormalModel \rightarrow DomainObject \rightarrow Class \rightarrow Instance \rightarrow RuntimeObject }
进一步:
RuntimeObject→State→Method→Behavior→Result→Feedback→Update\boxed{ RuntimeObject \rightarrow State \rightarrow Method \rightarrow Behavior \rightarrow Result \rightarrow Feedback \rightarrow Update }
因此理论不再停留在概念层,而进入程序运行层。
155.41 工程对象体系与机器个体
最终:
MachineIndividual={IndividualObject,CognitiveObjects,GoalObjects,CapabilityObjects,MethodObjects,DecisionObjects,BehaviorObjects,MemoryObjects,MaintenanceObjects,RuntimeObjects}MachineIndividual = \{ IndividualObject, CognitiveObjects, GoalObjects, CapabilityObjects, MethodObjects, DecisionObjects, BehaviorObjects, MemoryObjects, MaintenanceObjects, RuntimeObjects \}
可以表示为:
MachineIndividual
│
├── Identity
├── Structure
│
├── Cognition
│ ├── Object
│ ├── Attribute
│ ├── State
│ ├── Relation
│ ├── Scene
│ └── Knowledge
│
├── Goal
│ ├── Need
│ └── Goal
│
├── Capability
│
├── Method
│
├── Decision
│
├── Behavior
│ ├── Action
│ ├── Result
│ └── Feedback
│
├── Memory
│ ├── Memory
│ ├── Experience
│ └── History
│
├── Maintenance
│ ├── Risk
│ ├── Protection
│ ├── Conflict
│ ├── Diagnosis
│ └── Repair
│
└── Runtime
155.42 ICAI对象工程的核心原则
本章最终建立七条工程原则。
第一,对象必须有边界
ObjectA≠ObjectBObject_A\neq Object_B
第二,对象必须有身份
Object→IDObject\rightarrow ID
第三,对象必须能够描述状态
Object→StateObject\rightarrow State
第四,对象必须能够建立关系
ObjectA→Relation→ObjectBObject_A\rightarrow Relation\rightarrow Object_B
第五,对象必须具有明确职责
Object→ResponsibilityObject\rightarrow Responsibility
第六,计算必须由明确的Engine或Service承担
Object→EngineObject\rightarrow Engine
第七,理论对象必须能够映射到程序对象
TheoryObject→ProgramObject\boxed{ TheoryObject \rightarrow ProgramObject }
155.43 本章总结
第155章建立了ICAI从理论对象进入PHP面向对象工程的核心方法。
为什么使用面向对象:
Reality→Object→Structure→State→BehaviorReality \rightarrow Object \rightarrow Structure \rightarrow State \rightarrow Behavior
现实个体本身具有对象边界,因此程序工程需要使用对象模型对这些结构进行对应表达。
理论对象与程序对象之间建立:
TheoreticalObject→ObjectModel→PHPClass→ProgramInstance\boxed{ TheoreticalObject \rightarrow ObjectModel \rightarrow PHPClass \rightarrow ProgramInstance }
个体对象化:
Individual→MachineIndividualIndividual \rightarrow MachineIndividual
认知对象化:
Cognition→CognitiveObjectsCognition \rightarrow CognitiveObjects
行为对象化:
Behavior→BehaviorObjectsBehavior \rightarrow BehaviorObjects
最终形成完整工程对象体系:
Individual→CognitiveObject→Goal→Capability→Method→Decision→Behavior→Action→Result→Feedback→Memory→Maintenance→Runtime\boxed{ Individual \rightarrow CognitiveObject \rightarrow Goal \rightarrow Capability \rightarrow Method \rightarrow Decision \rightarrow Behavior \rightarrow Action \rightarrow Result \rightarrow Feedback \rightarrow Memory \rightarrow Maintenance \rightarrow Runtime }
而工程实现进一步形成:
ICAI理论→形式化模型→DomainObject→PHPClass→PHPInstance→Service/Engine→Repository→MySQL→Runtime\boxed{ ICAI理论 \rightarrow 形式化模型 \rightarrow Domain Object \rightarrow PHP Class \rightarrow PHP Instance \rightarrow Service/Engine \rightarrow Repository \rightarrow MySQL \rightarrow Runtime }
因此,ICAI面向对象工程的核心不是“使用PHP的Class”这么简单,而是建立一条严格的理论—对象—程序映射链:
理论对象是什么→程序对象就应该对应什么\boxed{ 理论对象是什么 \rightarrow 程序对象就应该对应什么 }
最终实现:
理论定义=对象模型=程序结构=Runtime结构\boxed{ 理论定义 = 对象模型 = 程序结构 = Runtime结构 }
这构成后续ICA I工程化实现的基础。