1.动作行为的继承
一个事物的行为动作可以是由自身定义的,也可以是继承自其描述者,或者继承自它所继承的事物。
2.动作行为继承的优先级
由于事物的行为动作可以是自己定义的,也可以是描述者或被继承的事物定义的,那么就有了优先级的问题。
X-Meta定义寻找行为动作的优先级是:事物本身->描述者->被继承的事物,找到了则不往后面找了。
3.动作行为继承的意义
动作行为继承实现了面向对象的功能,比如可以把描述者当作类,那么用它编写的实例就是对象,而对象此时继承了类所定义的行为。
动作事物的代码:
<?xml version="1.0" encoding="utf-8"?>
<InheritDescriptor name="InheritInstance" descriptors="xworker.example.thing.actions.InheritDescriptor"
extends="xworker.example.thing.actions.ExtendAction">
<description><![CDATA[<h3>动作的继承</h3>
<p> 事物的动作可以在事物本身的actions子节点下定义,也可以从其描述者和被继承的事物上继承。</p>
<h3>动作继承的顺序</h3>
<p> 一个动作首先从其自身找,其次从描述者上找,最后从继承上找,先找到的使用。</p>
<h3>动作继承的测试</h3>
<p> 请在当前事物编辑器的工具栏中找到相应的动作执行查看结果。</p>
<ul>
<li>描述者定义的动作:actionByDesc和actionOverwrite</li>
<li>被继承事物定义的动作:actionByExtend和actionOverwrite</li>
<li>当前事物定义的动作:actionByMySelf和actionOverwrite</li>
</ul>]]></description>
<actions descriptors="xworker.lang.MetaDescriptor3/@actions">
<GroovyAction name="actionByMySelf" code="println("action from myself");"></GroovyAction>
<GroovyAction name="actionOverwrite" code="println("overwrite action from myself");">
</GroovyAction>
</actions>
</InheritDescriptor>
描述者的代码:
<?xml version="1.0" encoding="utf-8"?>
<thing name="InheritDescriptor" descriptors="xworker.lang.MetaDescriptor3">
<actions>
<GroovyAction name="actionByDesc" code="println("action inherited from descriptor");"></GroovyAction>
<GroovyAction name="actionOverwrite" code="println("overwrite action inherited from descriptor");">
</GroovyAction>
</actions>
<attribute name="extends" inputtype="label" size="60"></attribute>
<attribute name="description" inputtype="html" showLabel="false"></attribute>
</thing>
继承事物的代码:
<?xml version="1.0" encoding="utf-8"?>
<thing name="ExtendAction" descriptors="xworker.lang.MetaDescriptor3">
<actions>
<GroovyAction name="actionByExtend" code="println("action inherited from extended thing");"></GroovyAction>
<GroovyAction name="actionOverwrite" code="println("overwrite action inherited from extended thing");">
</GroovyAction>
</actions>
</thing>