473,231 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Best way to model object inheritance?

Howdy all!

I'm working with XML schemas for the first time, so please be gentle!

I am working on a graphics program (in Java if it matters), and I have
decided to use XML files to store the "objects" that make up a drawing.

A subset of the class hierarchy might look like:

+-------------------------+
| |
| skitch.objects.Object |
| |
+------------+------------+
|
+---------------+---------------+
| |
+------------+------------+ +------------+------------+
| | | |
| skitch.objects.Line | | skitch.objects.Square |
| | | |
+-------------------------+ +-------------------------+

I could create a schema that understands lines, squares, and all the
other shapes, but I want the program to be easily extensible and to use
a more dynamic "plug-in" mechanism.

My current solution uses two schemas for each object, a "generic"
schema (object.xsd):

<?xml version="1.0" encoding="US-ASCII"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sk="xmlns://Skitch"
targetNamespace="xmlns://Skitch"
elementFormDefault="qualified">

<xs:include schemaLocation="basicTypes.xsd"/>

<xs:element name="object">
<xs:complexType>
<xs:sequence>
<xs:element name="objectData"/>
</xs:sequence>
<xs:attribute name="oid" type="sk:oidType" use="required"/>
<xs:attribute name="class" type="xs:string" use="required"/>
<xs:attribute name="schema" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

</xs:schema>

Once a file has been validated with this schema, the program can
discover the appropriate Java class to instantiate for this object (the
"class" attribute) and the class-specific schema (the "schema"
attribute).

Here's an example of a "line" object:

<?xml version="1.0" encoding="US-ASCII"?>

<sk:object xmlns:sk="xmlns://Skitch" oid="00000000"
class="skitch.objects.Line" schema="lineObject.xsd">

<sk:objectData>
<sk:start x="0.0" y="0.0"/>
<sk:end x="100" y="100"/>
<sk:color red="0" green="0" blue="0" alpha="255"/>
<sk:stroke width="1.0" cap="CAP_BUTT" join="JOIN_MITER"
miterLimit="10.0" dashPhase="0.0">
<sk:dash>
<sk:segment length="1.0"/>
<sk:segment length="1.0"/>
</sk:dash>
</sk:stroke>
</sk:objectData>

</sk:object>

And here's its class-specific schema:

<?xml version="1.0" encoding="US-ASCII"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sk="xmlns://Skitch"
targetNamespace="xmlns://Skitch"
elementFormDefault="qualified">

<xs:include schemaLocation="basicTypes.xsd"/>

<xs:element name="object">
<xs:complexType>
<xs:sequence>
<xs:element name="objectData" type="sk:lineObjectType"/>
</xs:sequence>
<xs:attribute name="oid" type="sk:oidType" use="required"/>
<xs:attribute name="class" type="xs:string" use="required"/>
<xs:attribute name="schema" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

</xs:schema>

(basicTypes.xsd can be found at
http://home.comcast.net/~i.pilcher/x...basicTypes.xsd.)

Things appears to be working so far, but validating every object twice
just seem inelegant.

Is there a better way?

Thanks!

--
================================================== ======================
Ian Pilcher i.*******@comcast.net
================================================== ======================
Jul 23 '05 #1
0 1060

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
3
by: Stephen S M WONG | last post by:
As C++ program supports objects with constructors/destructors/methods and data items, I'll assume C++ implementation on segment model computer, like a 80286 with different access restrictions on...
1
by: Jing You | last post by:
hi every one, I have got some confused problem when I try to write some custom object by javascript. Look at the example code here: <BODY> <script language="jscript">
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
5
by: wrecker | last post by:
Hi all, I have a few common methods that I need to use at different points in my web application. I'm wondering where the best place would be to put these? I think that I have three options. ...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
12
by: Doug | last post by:
Hi, I learned a little about the model view presenter pattern at a conference this last week and am experimenting with it. It's working pretty well but I have a question. I am trying to use...
9
by: Marc De Schrijver | last post by:
I'm designing an OO Model for a large application, and I have some question on how to model a particular situation; it's not directly related to C# but rather to general OO. The applicaiton will be...
23
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.