cubicweb #482289 Business Objects, Interfaces, Adapters, Namespaces [resolved]

We currently have a fairly simple Interface / Implementation model in CubicWeb. We define interface classes and we add the __implements__ statement in business object classes to declare which interfaces are implemented. It works well enough for now but we'll probably hit the namespace bug soon, i.e. two distinct interfaces defining the same method name and an entity implementing both interfaces. (We're already flirting with this problem with the parent() method of entities/IBreadCrumb and ITree).

I think ZCA already solves the problem and we've heard quite a few positive feedbacks. It might be worth taking a look at it seriously.

Otherwise, something easy to achieve in a few lines of not-so-magic Python is:

class MyEntity(object):
    def __init__(self):
        self.attr = 12

    ## IBreadCrumb implementation #################################
    class IBreadCrumbs(object):
        def parent(impl):
            print 'ibreadcrumbs.parent() of', impl.eid

    ## ITree implementation #######################################
    class ITree(object):
        def parent(impl):
            print 'itree.parent() of', impl.eid


x = rset.get_entity(0, 0)
bc = IBreadCrumbs(x)
print bc.parent() # ==> use the IBreadCrumb.parent() implementation
tree = ITree(x)
print tree.parent() # ==> use the ITree.parent() implementation

I can't remember if Java has a real solution to this problem, we might want to explore that also.

priorityimportant
typeenhancement
done in3.9.0
load2.000
load left0.000
closed by<not specified>