Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52056
| References | <ktqeho$f5i$1@news.albasani.net> <mailman.235.1375781442.1251.python-list@python.org> <520100F9.4010805@gmail.com> <mailman.254.1375797746.1251.python-list@python.org> <ktr56j$u7i$1@news.albasani.net> |
|---|---|
| Date | 2013-08-06 18:13 +0200 |
| Subject | Re: Class hierarchy problem |
| From | Jordi Riera <kender.jr@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.263.1375807105.1251.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
Are you using a db for that?
Django models would handle that pretty easily:
class Species(models.Model):
name = models.CharField()
class Genus(models.Model):
name = models.CharField()
species = models.ManyToManyField(
Species, related_name = 'genus_species'
)
then you can access species from genus by:
Genus.objects.all()[0].species.all()
and genus from species by:
Species.objects.all()[0].genus_species.all()
if you can afford this depends that would solve your issue I think.
more details:
http://stackoverflow.com/questions/9352662/how-to-use-the-reverse-of-a-django-manytomany-relationship
Regards
Jordi
On Tue, Aug 6, 2013 at 5:36 PM, BrJohan <brjohan@gmail.com> wrote:
> On 06/08/2013 16:02, Chris Angelico wrote:
>
> My classhierarchy is like a multilevel tree where each non-leaf node
>>> (class)
>>> is given knowledge about its nearest subclasses and their 'capacities'.
>>>
>>> So, my idea is to let the 'upper' class recursively choose which of its
>>> nearest subclasses is the 'correct' one, until approaching a 'leaf' class
>>> from which the instance should be created. And, given my knowledge that a
>>> solution along the lines of this idea has been designed and was working,
>>> I'm
>>> still hopeful ... (or I'll have to investigate all those old backup-DVDs)
>>>
>>
>> [ responding on-list - I hope it was mere oversight that had this come
>> privately to me alone ]
>>
>> This is code smell; this recursive search for the "right" class seems
>> likely to be wrong. Can you have the classes perhaps register
>> themselves in some way? On what basis is a superclass to determine
>> that one of its subclasses should handle this request?
>>
>> ChrisA
>>
>>
>
> Consider a botanical classification system (somewhat analogous to my
> 'problem' as it effectively is related to classification of entities):
>
> A Domain should know about its Kingdoms,
> a Kingdom should know about its Phylums,
> ...
> a Genus should know about its Species.
>
> Of course it is possible to implement such a decision tree as a 'factory'.
> However, I would rather prefer to encapsulate those decisions at the class
> level where they 'belong'.
>
> BrJohan
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
--
- Jordi Riera, Connecting people.
+33 662217507
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Class hierarchy problem BrJohan <brjohan@gmail.com> - 2013-08-06 11:10 +0200
Re: Class hierarchy problem Chris Angelico <rosuav@gmail.com> - 2013-08-06 10:30 +0100
Re: Class hierarchy problem Chris Angelico <rosuav@gmail.com> - 2013-08-06 15:02 +0100
Re: Class hierarchy problem BrJohan <brjohan@gmail.com> - 2013-08-06 17:36 +0200
Re: Class hierarchy problem Joe Junior <joe.fbs.junior@gmail.com> - 2013-08-06 13:23 -0300
Re: Class hierarchy problem Jordi Riera <kender.jr@gmail.com> - 2013-08-06 18:13 +0200
Re: Class hierarchy problem Chris Angelico <rosuav@gmail.com> - 2013-08-06 18:12 +0100
Re: Class hierarchy problem Terry Reedy <tjreedy@udel.edu> - 2013-08-06 19:13 -0400
Re: Class hierarchy problem Ben Finney <ben+python@benfinney.id.au> - 2013-08-07 11:58 +1000
Re: Class hierarchy problem Peter Otten <__peter__@web.de> - 2013-08-06 11:34 +0200
Re: Class hierarchy problem Steven D'Aprano <steve@pearwood.info> - 2013-08-06 09:36 +0000
pexpect, loading an entry field inq1ltd <inq1ltd@inqvista.com> - 2013-08-06 11:05 -0400
Re: pexpect, loading an entry field "Lakshmipathi.G" <lakshmipathi.g@gmail.com> - 2013-08-06 22:04 +0530
Re: pexpect, loading an entry field inq1ltd <inq1ltd@inqvista.com> - 2013-08-06 14:03 -0400
Re: pexpect, loading an entry field "Lakshmipathi.G" <lakshmipathi.g@gmail.com> - 2013-08-07 13:40 +0530
csiph-web