开发者

Should we declare a simple type explicitly even for a string type in venetian blinds pattern

I am using the venetian blinds pattern to design my XML schema and it requires that all the types are declared at the global level and all the elements use the 开发者_运维百科types defined in the global scope.

My question is this:

If I want to declare 2 elements which are simple strings with no other restriction, should I declare them in the global scope and then use them? Or can I directly declare a simple type inside the element itself? Am I breaking the venetial blinds in the second scenario I listed below?

For example, I can do one of the two:

<xsd:schema>
<xsd:simpleType name="ApplicantName">
    <xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:simpleType name="ApplicantCountry">
    <xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:element name="Application">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="ApplicantName" type="ApplicantName"/>
            <xsd:element name="ApplicantCountry" type="ApplicantCountry"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
</xsd:schema>

Or I can use this.

<xsd:schema>
<xsd:element name="Application">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="ApplicantName" type="xsd:string"/>
            <xsd:element name="ApplicantCountry" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

</xsd:element>
</xsd:schema>


Well, why did you choose to follow this pattern? Which option provides the benefits that are promised by the pattern? Answer those questions and I think you have your answer.

It seems to me that the pattern calls for the first approach. Whether the pattern actually has value, or whether it should be followed so rigorously is for you to decide. At the heart of the matter is the question of what you are trying to achieve by using the pattern in the first place.


I'd say: It depends. The goal of Venetian Blinds is to reuse types but unless some of your elements share a common restriction like, for example, field length imposed by a backend database you won't gain anything from following this pattern religiously.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜