XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] [XSD question] Does ref'ing to the same global elementdeclaration multiple times violate the Don't Repeat Yourself principle?

Code that's written to optimize some metric such as minimising the number of @ref attributes is almost inevitably going to be bad code, if it's done at the expense of other metrics such as complexity and readability. Coding is a creative discipline and requires human intelligence, not blind adherence to rules. Rules like DRY are instructive, but they are there to be broken, or at any rate, to be considered alongside other desiderata.

The actual goal here (the objective underlying DRY) is "potential for change" - you want a schema that's easy to change when the requirements change. Potential for change is what drives an awful lot of software engineering, yet it's a quality that's impossible to measure, because you don't know what changes are going to be required in the future. That's why it requires human intelligence.

There may be cases where potential for change requires duplication of code: an example might be that ISBN and PhoneNumber should be different data types even if they happen to have the same format, because they are only the same by coincidence and that could change. Only a human knows that.

Michael Kay
Saxonica

> On 6 Jan 2022, at 14:42, Roger L Costello <costello@mitre.org> wrote:
> 
> Hi Folks,
> 
> Thank you for your responses. Very good, ref'ing multiple times to a global element declaration does not violate DRY.
> 
> Below I have slightly modified the XML Schema. I created an xs:group and placed the ref's to Title and Publisher inside the xs:group. Now the Book and Magazine elements ref to the xs:group. In the previous XML Schema design there were two ref's to Title and two ref's to Publisher:
> 
> <xs:element ref="Title" />
> <xs:element ref="Title" />
> <xs:element ref="Publisher" />
> <xs:element ref="Publisher" />
> 
> In the new design there is only one ref to Title and one ref to Publisher (the ref's are inside xs:group). But now there are two ref's to the xs:group
> 
> <xs:group ref="Title-and-Publisher" />
> <xs:group ref="Title-and-Publisher" />
> 
> In the previous design there were four ref's:
> 
> <xs:element ref="Title" />
> <xs:element ref="Title" />
> <xs:element ref="Publisher" />
> <xs:element ref="Publisher" />
> 
> In the new design there are also four ref's:
> 
> <xs:group ref="Title-and-Publisher" />
> <xs:group ref="Title-and-Publisher" />
> <xs:element ref="Title" />
> <xs:element ref="Publisher" />
> 
> Suppose Book and Magazine have three common elements: Title, Publisher, and Author. In the old design there would be six ref's:
> 
> <xs:element ref="Title" />
> <xs:element ref="Title" />
> <xs:element ref="Publisher" />
> <xs:element ref="Publisher" />
> <xs:element ref="Author" />
> <xs:element ref="Author" />
> 
> In the new design there would be five ref's:
> 
> <xs:group ref="Title-and-Publisher-and-Author" />
> <xs:group ref="Title-and-Publisher-and-Author" />
> <xs:element ref="Title" />
> <xs:element ref="Publisher" />
> <xs:element ref="Author" />
> 
> You have stated that ref's do not violate DRY. Here we see an opportunity to reduce the number of ref's by using xs:group. Is a design that uses less ref's more DRY-compliant than a design that uses more ref's?  /Roger 
> ----------------------------------------------
> <xs:element name="Bookstore">
>    <xs:complexType>
>        <xs:sequence>
>            <xs:element name="Book" maxOccurs="unbounded">
>                <xs:complexType>
>                    <xs:sequence>
>                        <xs:group ref="Title-and-Publisher" />
>                        ...
>                    </xs:sequence>
>                </xs:complexType>
>            </xs:element>
>            <xs:element name="Magazine" maxOccurs="unbounded">
>                <xs:complexType>
>                    <xs:sequence>
>                        <xs:group ref="Title-and-Publisher" />
>                        ...
>                    </xs:sequence>
>                </xs:complexType>
>            </xs:element>
>        </xs:sequence>
>    </xs:complexType>
> </xs:element>
> 
> <xs:group name="Title-and-Publisher">
>    <xs:sequence>
>        <xs:element ref="Title" />
>        <xs:element ref="Publisher" />
>    </xs:sequence>
> </xs:group>
> 
> <xs:element name="Title" type="xs:string" />
> <xs:element name="Publisher" type="xs:string" />
> ...
> 
> _______________________________________________________________________
> 
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
> 
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
> 



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS