On 01/07/2014 07:35 AM, Zhihua Zheng wrote:
> mn... I think it works for me.
> Thanks for your advice.
> 
> P.S. They implement class, why not inheritance?

I started working on that a very very long time ago (2006), and the
short answer is that it's not a very easy thing to do correctly. It's
not just about the UI showing input fields for the inherited properties,
but also how to make queries work with both classes, how to adapt the
data model APIs, how to design the right user experience which would
allow both easily managing inheritance and not cause data model
inconsistencies, should property overrides be allowed, etc.

I agree, though, that XClass inheritance would be a great thing, and if
enough users request it someone might invest the time needed to
implement it.

> 
> 2014/1/7 Valdis Vītoliņš <valdis.vitol...@odo.lv>
> 
>> If you add different objects from several classes to XWiki document,
>> common problem is that for document representation sheet of first found
>> class is used.
>> Therefore for composite objects you need to add
>> XWiki.DocumentSheetBinding object
>> which points to sheet document, with content like this (not tested!):
>> {{velocity}}
>> #set($obj1=$doc.getObject('Space.Obj1Class'))
>> #set($obj2=$doc.getObject('Space.Obj2Class'))
>> ...
>> #if($obj1)
>> #set($class1=obj1.xWikiClass)
>> #foreach($prop in $class1.properties)
>> |$prop.prettyName|$doc.display($prop.getName($obj1))
>> #end
>> #end
>> ...
>> #if($obj2)
>> ....
>>
>> Look at
>> http://extensions.xwiki.org/xwiki/bin/view/Extension/Sheet+Module
>> for more. Note that you can save all these objects in specific template.
>>
>> Valdis
>>> hi,
>>>
>>>
>>> Thanks for your answer.
>>> Currently I am using a set of classes to represent my data, for
>>> display part they just need to directly show the properties. If I use
>>> composit, for the common part I need to identify if it's common, and
>>> there will be some "if-else" in each of the subclasses.
>>>
>>>
>>> I just wandering if we can have some auto-load, so that I don't need
>>> to use "if-else" everywhere, and it will be easy to maintain, just
>>> like the inherited class.
>>>
>>>
>>>
>>> 2014/1/5 Valdis Vītoliņš <valdis.vitol...@odo.lv>
>>>         If you mean these classes defined in class editor defined
>>>         in .../xwiki/bin/view/XWiki/XWikiClasses
>>>         AFAIK these doesn't support extension.
>>>
>>>         So, you need to use composition instead. Add object with type
>>>         of the
>>>         common class, and for few other documents add another object
>>>         with type
>>>         of "extended" class.
>>>
>>>         You will need to adjust class sheet object to display fields
>>>         of other
>>>         tyepe of objects also (look at
>>>         http://extensions.xwiki.org/xwiki/bin/view/Extension/Sheet
>>>         +Module )
>>>
>>>         Valdis
>>>
>>>         > hi,
>>>         >
>>>         > the Class I mean is XClass, which is used in Wiki pages.
>>>         >
>>>         > thanks,
>>>         > B.R./ZZH
>>>         >
>>>         >
>>>         > 2014/1/5 Zhihua Zheng <zhihu...@gmail.com>
>>>         >
>>>         > > hi all,
>>>         > >
>>>         > > I have couple of classes they are similar, most of them
>>>         are the same, but
>>>         > > some small parts are different. So that I want to use a
>>>         arch that there is
>>>         > > a common class holds all the common properties, and the
>>>         real classes are
>>>         > > inherited from the common.
>>>         > > But how to achieve that?
>>>         > >
>>>         > > thanks!
>>>         > >


-- 
Sergiu Dumitriu
http://purl.org/net/sergiu
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to