[Thuban-devel] Re: RfD: Support for layer specific resources
Bernhard Herzog
bh at intevation.de
Fri Jul 16 21:01:34 CEST 2004
Martin Schulze <joey at infodrom.org> writes:
> Sorry for the flood of mails. Attached please find the test case
> and the real implementation for the Mapping class. Hope this is
> what you want.
Almost there.
> class Mapping:
The name is a bit too generic. Maybe ClassMapper?
> """
> Implements a mapping of class pairs
> """
Actually, it's a mapping of classes (and instances thereof) to arbitrary
objects. The renderer extensions are usually functions, for instance.
> mapping = []
What's that for?
> def __init__(self):
> mapping = []
>
> def register_class(self, key_class, client_class):
> self.mapping.append((key_class, client_class))
I'd simply call this method "add".
> def get_class(self, instance):
> for key_class, client_class in self.mapping:
> if isinstance(instance, key_class):
> return client_class
> return None
And this just "get". Makes the interface a little more like that of a
normal dict. Also, client_class isn't restricted to classes. It can be
an arbitrary Python object, so "obj" or "value" would be better.
> def has_mapping(self, instance):
> return self.get_class(instance) is not None
Maybe just "has". The dict equivalent would be "has_key" but that
doesn't fit this class all that well, though, because the instances
aren't the keys, although the behave a bit like ones.
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://sketch.sourceforge.net/
Thuban http://thuban.intevation.org/
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)