W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2002

Re: Schema Design: Composition vs Subclassing

From: Jeff Rafter <jeffrafter@defined.net>
Date: Tue, 2 Apr 2002 23:38:30 -0600
Message-ID: <013e01c1dad1$c9687250$32f5d90c@C1980223A>
To: "Roger L. Costello" <costello@mitre.org>, <xmlschema-dev@w3.org>
<massive_snip/>

> What are your thoughts on this?  /Roger

I have run into the same issues-- one of the determining factors is what I
am using as my "base class" or XML Schema base type. In general I agree that
using group is a much better and scalable design. It avoids all kinds of
nasty stuff.  OTOH, I have found it easier when designing XML Schemas that
actually represent Object Oriented serialized Objects that the only logical
way is by using inheritence.

The reason for this is that the generating software may not have the ability
to introspect all levels (depending on language and availability). For
example let's say I am doing this in Delphi (Object Pascal)--

My base type will look something like

<xs:complexType name="TObject">
  <xs:sequence>
    <xs:element
      name="TObject"
      type="target:TObject"
      minOccurs="0"
      maxOccurs="unbounded" />
  </xs:sequence>
  <xs:attribute name="order" type="xs:positiveInteger" />
  <xs:attribute name="flags" type="xs:string" />
  <xs:attribute name="id" type="xs:ID" />
</xs:complexType>

It is a TObject that may contain an unlimited number of TObjects. At this
level I have no idea what will use this as its ancestor in the future. In
the future I may have a "TComponent" that adds properties (subelements), but
can still contain multiple TObject descendents within it.

<xs:complexType name="TComponent">
  <xs:complexContent>
    <xs:extension base="target:TPersistent">
      <xs:sequence>
        <xs:element
          name="Tag"
          type="xs:int"
          minOccurs="0" />
        <xs:element
          name="Left"
          type="xs:integer"
          minOccurs="0" />
        <xs:element
          name="Top"
          type="xs:integer"
          minOccurs="0" />
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

This allows me to use the xsi:type facility within the instance document to
actually specify what kind of TObject I am using in the instance.

All the best,
Jeff Rafter
Defined Systems
http://www.defined.net
XML Development and Developer Web Hosting
Received on Wednesday, 3 April 2002 00:40:26 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:30 GMT