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

Re: What good is Restriction?

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 8 Jul 2002 23:21:34 +0100
Message-ID: <0211045907.20020708232134@jenitennison.com>
To: xmlschema-dev@w3.org, Gary Cramblitt <garycramblitt@comcast.net>

Hi Gary,

> Quoting from the XML-Schema Primer, when deriving a new type
> by restricting a base complex type...
> ---
> Notice that types derived by restriction must repeat all the 
> components of the base type definition that are to be included 
> in the derived type
> ---
> So if I must repeat everything in the base type as well as the 
> restrictions, what good is it?  Why not just create a new type 
> and be done with it?  My conclusion is that while XSD claims 
> to be object oriented, it doesn't support full inheritance, at least 
> not in this instance.  Maybe this is similar to Microsoft's  
> "Interface Inheritance"?  Anybody know why this requirement 
> was put in the spec?  Just wondering...

First, the XML Schema Primer isn't quite accurate here: not *all*
components of a type derived by restriction have to be repeated --
attribute declarations/references are inherited from the base type to
the derived type, so you don't have to repeat them.

The main reason to use derivation by restriction rather than creating
a new type is because it sets up an explicit relationship between the
base type and the derived type. This is important for two reasons.

First, it means that it's possible to do things like declaring an
element with the base type and creating a substitution group in which
all the members of the substitution group have a type derived (by
restriction) from that main type. You tend to see this happening quite
a lot when people define a "list" type, containing "item" elements,
and then want to define a "listOfX" type derived from the "list" type
but containing "X" elements. (I guess in a way that's a circular
argument -- you use a derived type so that you can derive other
types...)

Second, the point of having type hierarchies outside the schema itself
is so that other applications can use them within their own
processing. For example, in XQuery you might be able to do:

  if   ($X instance of element of type my:item)
  then ...
  else ...

My guess is that when we start seeing applications that take advantage
of the type hierarchy, we'll start seeing derivation by restriction as
more important/useful than we do currently.
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Monday, 8 July 2002 18:21:36 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:57 UTC