473,397 Members | 2,084 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,397 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 1069

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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.