IMHO this will turn out to be a mistake later on. I know, its tempting to special-case some elements in a derived class but in my experience it always ended up with a more complicated code than if you just stick with a single element class. It is a single algebraic structure, so all elements should be expressible in a single object. Also, any performance gains that you imagine from specializing the element implementation will be counterbalanced by more complicated checks in operations and the _element_constructor_.
On Saturday, August 23, 2014 9:53:47 AM UTC+1, Daniel Krenn wrote: > > I'm going through [1] to construct a new algebraic structure. I have one > parent, but want more than one elements, which should be associated to > this parent. More precisely, I have the following classes: > > +- MyElementBase > +-- MyElementA (derived from MyElementBase) > +-- MyElementB (derived from MyElementBase) > > In [1] it says, we should use > return self.element_class(data) > in Parent._element_constructor_ to create objects. This creates a class > derived from Parent.Element (which IMHO should be MyElementBase) and > Parent.category().element_class. > > How can I create "the correct" instance of MyElementA and MyElementB > inside _element_constructor_ depending on the input? (I want to do this, > since MyElementA is a specialized version of MyElementBase for some > inputs; similar MyElementB) > > Daniel > > [1] > http://www.sagemath.org/doc/thematic_tutorials/coercion_and_categories.html > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.