[MOBY-dev] hierarchy and castings in Moby

Iván Párraga García ivanp at mmb.pcb.ub.es
Fri May 18 10:39:42 UTC 2007


Hi,

Another philosophical question about moby... Unfortunately moby does not
support the concept of templates (in the C++ sense), so there is a no
clear way to build container objects (let's say an array or a hash map,
for example). A solution could be the concept of generics (like in Java
prior to version 1.5), where you define a container as containing the
most generic type of object in the hierarchy (the Object "class") and
then the container can hold any kind of contents. Afterwards, if you
want to emphasize what is the content of a container you can specialize
by subclassing. Not sure if I explain myself, I mean something like this:

The root container

<registerObjectClass>
    <objectType>Map</objectType>
    ../..
    <Description>
        <![CDATA[An object that maps keys to values. A map cannot
contain duplicate keys; each key can map to at most one value. Size must
contain the number of MapEntries and keyRole and valueRole are
descriptions of the meaning of the key and value elements for this
mapping]]>
    </Description>
    <Relationship relationshipType="ISA">
        <objectType>Object</objectType>
    </Relationship>
    <Relationship relationshipType="HAS">
        <objectType articleName="entries">MapEntry</objectType>
    </Relationship>
    <Relationship relationshipType="HASA">
        <objectType articleName="size">Integer</objectType>
        <objectType articleName="keyRole">String</objectType>
        <objectType articleName="valueRole">String</objectType>
    </Relationship>
</registerObjectClass>

The content:

<registerObjectClass>
    <objectType>MapEntry</objectType>
    ../..
    <Description>
        <![CDATA[A convinient object to map two arbitray objects]]>
    </Description>
    <Relationship relationshipType="ISA">
        <objectType>Object</objectType>
    </Relationship>
    <Relationship relationshipType="HASA">
        <objectType articleName="key">Object</objectType>
        <objectType articleName="value">Object</objectType>       
    </Relationship>
</registerObjectClass>

and then an specialized container:

<registerObjectClass>
    <objectType>ResidueFloatMap</objectType>
    ../..
    <Description>
        <![CDATA[It's a map where the entries are <Residue,Float>. This
is only a semantic inheritance]]>
    </Description>
    <Relationship relationshipType="ISA">
        <objectType>Map</objectType>
    </Relationship>   
</registerObjectClass>

Because of inheritance, the ResidueFloatMap, will contain MapEntry
objects, but the programmer (by convention) must guarantee if using this
datatype that the contents of the MapEntry must be Residue and Float
respectively. I think this should work because, obviously, any moby
class inherits of the root Object, isn't it?

Ok, my question is if this approach is right. I had the impression that
it should be, but I'm having some parsing problems with the MoSeS -
jMoby and I'm not sure if is because of this approach or it it is a bug.
An additional question (I couldn't check it because of these previous
problems): to have this solution working, I would need to perform
casting conversion in the source of the services that receive an
specialized container, something like this (excuse my pseudo-code):

ResidueFloatMap map = ...
Entry[] entries = map.getMoby_Entries();
Residue residue = ((Residue)(entries[0].getMoby_key()));

Is this right/possible? If not, any way to do it?

Thanks,

-- 
------------------------------------------------
Iván Párraga García
Computer Scientist
Molecular Modelling & Bioinformatics Unit
INB - Instituto Nacional de Bioinformática
Josep Samitier 1-5
08028 Barcelona
Spain
tel.: +34 93 403 71 55
fax.: +34 93 403 71 57
e-mail: ivanp at mmb.pcb.ub.es
group page: http://mmb.pcb.ub.es 
pgp key: http://mmb.pcb.ub.es/~ivanp/pubkey.asc
------------------------------------------------




More information about the MOBY-dev mailing list