Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52055
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joe.fbs.junior@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.038 |
| X-Spam-Evidence | '*H*': 0.92; '*S*': 0.00; 'tree': 0.05; 'responding': 0.07; 'instances.': 0.09; 'means,': 0.09; 'cc:addr:python-list': 0.11; '"is': 0.16; '"right"': 0.16; 'created.': 0.16; 'investigate': 0.16; 'kingdom,': 0.16; 'nearest': 0.16; 'subclasses': 0.16; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; "shouldn't": 0.24; 'subject:problem': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'chris': 0.29; 'related': 0.29; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 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; 'alone': 0.33; 'knowledge': 0.35; 'classes': 0.35; 'problem.': 0.35; 'one,': 0.35; 'received:google.com': 0.35; "i'll": 0.36; 'possible': 0.36; 'should': 0.36; 'so,': 0.37; 'level': 0.37; 'implement': 0.38; 'handle': 0.38; 'pm,': 0.38; 'rather': 0.38; 'hope': 0.61; 'kingdom': 0.61; 'course': 0.61; "you're": 0.61; 'such': 0.63; 'choose': 0.64; 'talking': 0.65; 'to:addr:gmail.com': 0.65; 'effectively': 0.66; 'determine': 0.67; "'upper'": 0.84; 'domain,': 0.84; 'working,': 0.84; '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=ESYl1pNCijlLFYsPFmtle823STMeBLzp6xbIIeuiokc=; b=wSlVzZLabfuNNo6ulnvCJ0AswPQ0gf3HhqPDNTTmD8QfDj5kDRAN7a1qsD1wcnzXrG 5ewCvPTiNlJ65B30mcKblYt5M4MPAkLa7eR0Uy+oFsfrNblGgcb7WJHDcnIlBbL1D6Ll 2uO+krsQ8nB7qW8p/jwJzdMoLARmz5c5zLtacXN5H1suuEXMh0bIugx+PIZEqFF8eRWT njBGxisaRlsWme/CG1i/Ecgse4IMs6iOwi/REzyTqw9MOMfBo7q2vhWbc/Cjc1a6+Jm+ MjdY2gUfyK6JWTwFRyBgygKwVHbrIE5Gp4F5n6qzxx3Kawlb5fyyMET+nX6zGMcEbUaJ AVUw== |
| MIME-Version | 1.0 |
| X-Received | by 10.224.122.194 with SMTP id m2mr4514385qar.81.1375806238629; Tue, 06 Aug 2013 09:23:58 -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 13:23:58 -0300 |
| Subject | Re: Class hierarchy problem |
| From | Joe Junior <joe.fbs.junior@gmail.com> |
| To | BrJohan <brjohan@gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Mailman-Approved-At | Tue, 06 Aug 2013 18:38:24 +0200 |
| Cc | 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.264.1375807105.1251.python-list@python.org> (permalink) |
| Lines | 53 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1375807105 news.xs4all.nl 15908 [2001:888:2000:d::a6]:53528 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52055 |
Show key headers only | View raw
On Tue, Aug 6, 2013 at 12: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 > -- I think it's a "has a" vs a "is a" problem. A Domain has a Kingdom, a Kingdom is not a Domain, so it shouldn't actually inherit Domain. In this case you should use composition instead of inheritance. When you say that a A Domain should know about it's Kingdons note that you're talking about a specific Domain and it's specific Kingdons, which means, a Domain instance and various Kingdom instances. JoeS
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