Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52056

Re: Class hierarchy problem

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kender.jr@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.083
X-Spam-Evidence '*H*': 0.83; '*S*': 0.00; 'that?': 0.05; 'tree': 0.05; 'responding': 0.07; 'cc:addr:python-list': 0.11; 'django': 0.11; '"right"': 0.16; 'created.': 0.16; 'investigate': 0.16; 'nearest': 0.16; 'subclasses': 0.16; 'think.': 0.16; 'wrote:': 0.18; 'seems': 0.21; '8bit%:5': 0.22; '>>>': 0.22; 'aug': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; 'subject:problem': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'chris': 0.29; 'related': 0.29; 'skip:g 30': 0.30; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'node': 0.31; 'oversight': 0.31; 'way?': 0.31; 'class': 0.32; 'themselves': 0.32; 'url:python': 0.33; 'alone': 0.33; 'skip:b 30': 0.33; 'knowledge': 0.35; 'classes': 0.35; 'one,': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; "i'll": 0.36; 'possible': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'level': 0.37; 'implement': 0.38; 'skip:& 10': 0.38; '8bit%:4': 0.38; 'depends': 0.38; 'handle': 0.38; 'issue': 0.38; 'pm,': 0.38; 'rather': 0.38; 'skip:b 40': 0.39; '8bit%:6': 0.40; 'url:mail': 0.40; 'solve': 0.60; 'hope': 0.61; 'kingdom': 0.61; 'course': 0.61; 'name': 0.63; 'such': 0.63; 'choose': 0.64; 'connecting': 0.64; 'more': 0.64; 'by:': 0.65; 'to:addr:gmail.com': 0.65; 'effectively': 0.66; 'determine': 0.67; 'details:': 0.80; "'upper'": 0.84; '5:36': 0.84; 'working,': 0.84; 'afford': 0.91; 'subject:Class': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Ble7W5ONs4kY1kwp51Qh/s0ouPuaPvrEr9d+iOz/ZMA=; b=sBaZILYDJSPn3Kh+n0FgvRerUtPPr9bjUlpyNtsKop0hOC1mclzgQTIk/2+/ovk2+4 2Bits6DPWlNd3QuCgdgNPWegNhsxPl+vQ7xUlMfX1g4hMN0cLaf//OXy70kSoL/yLh9c s10n/+qTjCAPY93HiX4hGaK1yzru5fqqIgkFPEPDWBjQUpWfZhImzU6yxHKykkHZ97AM 4zhv/E7jkgac52YfSAiQ2KpsUrWQptdLyCegZuTzOPeaDArKoo7V4Lq9n4KJdnH6ZVT6 LrfgjA3flH5nxFIyklQuk0THPYFqnEZ/aXa3L+404Ei3IYCeg69c6A2FDRcw0Cu4Dwv/ RXPw==
MIME-Version 1.0
X-Received by 10.66.240.67 with SMTP id vy3mr4002164pac.141.1375805635597; Tue, 06 Aug 2013 09:13:55 -0700 (PDT)
In-Reply-To <ktr56j$u7i$1@news.albasani.net>
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 Tue, 6 Aug 2013 18:13:55 +0200
Subject Re: Class hierarchy problem
From Jordi Riera <kender.jr@gmail.com>
To BrJohan <brjohan@gmail.com>
Content-Type multipart/alternative; boundary=047d7b15ab7f309bf604e349b603
X-Mailman-Approved-At Tue, 06 Aug 2013 18:38:24 +0200
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.263.1375807105.1251.python-list@python.org> (permalink)
Lines 170
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375807105 news.xs4all.nl 15879 [2001:888:2000:d::a6]:53527
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52056

Show key headers only | View raw


[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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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