Hi Volker, On 2013-07-28, Volker Braun <vbraun.n...@gmail.com> wrote: > The __classcall__ is used just as a shortcut (well arguably its not shorter > but lets say it is for the sake of the argument) for the factory function > pattern.
Sure. But the question is: SHOULD there be more than a factory function? After all, we have a class, and we call the class as if to create an instance---but what we get is in fact not an instance of this class, but is instance of a *totally* different class. OK, it is possible, Python let's you do it. But not all what can be done should be done. I have nothing against the following pattern: class C(UniqueRepresentation): @staticmethod def __classcall_private__(cls, *args,**kwds): if <condition 1>: return A(*args,**kwds) else: return B(*args,**kwds) # define some general methods of C class B(C): def __init__(...): ... # define some methods of B that aren't in C class A(C): def __init__(...): ... # define some methods of A that aren't in C Then, calling C(...) would return an instance of either A or B, which would be a unique representation, since C uses __classcall_private__, not __classcall__, and hence the caching of UniqueRepresentation is available for A and B. And I think this pattern is totally fine, since C(...) returns instances of sub-classes of C (namely of A resp. B)---hence, it returns instance of C! I could imagine that a similar pattern would be available for Partition versus PartitionTuple. However, if C(...) is supposed to return objects that have nothing to do with the class C, then C should really not be a class, but just a plain factory function. Best regards, Simon -- 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/groups/opt_out.