创建复杂模型的技巧是使用继承,比如下面的例子。
<?xml version="1.0" encoding="utf-8"?>
<thing name="ThingCollection" descriptors="xworker.lang.MetaDescriptor3"
description="<p>使用继承可以构建复杂的事物。</p>">
<thing name="Shell" extends="xworker.swt.widgets.Shell"></thing>
<thing name="SimpleControl" extends="xworker.http.controls.SimpleControl"></thing>
<thing name="Person" extends="xworker.example.thing.creatething.Person"></thing>
</thing>
如上面的代码,ThingCollection定义了Shell、SimpleControl和Person等子事物节点,这些子节点继承了SWT的Shell模型、WEB框架模型和Person模型等,这样在ThingCollection中就可以编写这些模型了。
这样ThingCollection模型就通过继承而丰富了自己。

如上图的ThingCollection的实例,可以在它下面编写SWT、WEB和Person的模型了,这时ThingCollection是一个复杂的组合模型。
<?xml version="1.0" encoding="utf-8"?>
<ThingCollection name="ThingCollectionInstance" descriptors="xworker.example.thing.creatething.ThingCollection"
mammalAttribute="test" animalAttribute="test" creatureAttribute="test">
<description><![CDATA[<h3>继承在描述者上的作用</h3>
<p> 在描述者上使用继承可以轻松定义复杂的事物,首先它可以像面向对象那种通过类
(描述者相当于类)的继承从而定义复杂的事物,从而可以让事物的属性和子事物更加丰富。</p>]]></description>
<Shell name="shell" text="一个窗口" RESIZE="true" width="640" height="480"></Shell>
<Person name="Tom" age="30">
<Child name="Smith"></Child>
</Person>
<SimpleControl name="helloWorldWeb">
<view>
<otherHeads><![CDATA[<meta http-equiv="content-type" content="text/html; charset=utf-8">
<LINK REL ="stylesheet" TYPE="text/css" HREF="fckeditor/2_6beta1/editor/css/fck_editorarea.css" TITLE="Style"/>
<script type="text/javascript" src="js/xworker/InnerBrowserUtil.js"></script>]]></otherHeads>
<htmlCode htmlCode="<h3>HelloWorld</h3>"></htmlCode>
</view>
<result name="success" value="xworker.example.thing.creatething.ThingCollectionInstance/@helloWorldWeb/@view"></result>
</SimpleControl>
</ThingCollection>
Copyright © 2007-2014 XWorker.org 版权所有