Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'classes,': 0.05; 'irc': 0.05; 'though:': 0.07; 'classes.': 0.09; 'decorator': 0.09; 'method,': 0.09; 'creates': 0.14; '23,': 0.16; 'defined.': 0.16; 'letting': 0.16; 'separated': 0.16; 'subject:OOP': 0.16; 'files.': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'email addr:gmail.com>': 0.22; 'separate': 0.22; 'logical': 0.24; "haven't": 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'message- id:@mail.gmail.com': 0.30; 'asked': 0.31; 'class': 0.32; 'another': 0.32; 'becomes': 0.33; 'subject:from': 0.34; 'could': 0.34; 'problem': 0.35; 'received:google.com': 0.35; 'subject:one': 0.36; 'problems': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'tell': 0.60; 'mentioned': 0.61; 'new': 0.61; 'making': 0.63; 'subject:Moving': 0.84 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 :content-type; bh=M7K1bBTeemcr2BUHwYKhP+WSKT8/VlC6byexhuE8k+w=; b=pD9y0VPdhMjGx+ZXCzBbL8ZyP0omBA9G6AYA6H03QtNuOIAAIWDS1zSdSfibyb381i nhdfjX5z0Lh2VilH/MZLtQQqxfnSoCt1CD1Q9yAjM0QUJbqGIuxNPq10g+8weQRXCWMU v2gGTOhJw22M6UGasr6KdcCHNZVgAMSH4+0XiZE64GAQD9le4egUmVGOfJpK8KzpwIi3 7L3iR/dyGtJnAwi/h+wi3s65W4X0p/dTso+bIHFP4qRJeqgYugjVb4oGxQ8QDoRuKDpU Kgl2vpWEC4B/4dJSNQDXtyOXA78FSb6gifFE4icP2oMz1dkpWmBUWF+oz0UwYL0iruiw CrUQ== MIME-Version: 1.0 X-Received: by 10.66.160.34 with SMTP id xh2mr447864pab.109.1398288204980; Wed, 23 Apr 2014 14:23:24 -0700 (PDT) In-Reply-To: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> References: <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com> Date: Wed, 23 Apr 2014 15:23:24 -0600 Subject: Re: Moving to an OOP model from an classically imperitive one From: Ian Kelly To: Python Content-Type: multipart/alternative; boundary=047d7bacb37ec25ff104f7bc57e6 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398288213 news.xs4all.nl 2939 [2001:888:2000:d::a6]:41947 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70552 --047d7bacb37ec25ff104f7bc57e6 Content-Type: text/plain; charset=UTF-8 On Apr 23, 2014 5:01 PM, wrote: > I asked on IRC and it was sugested that I use multiple classes, however I see no logical way to separate a SubuserProgram object into multiple classes. You say you already have the methods logically separated into files. How about adding one abstract class per file, and then letting SubuserProgram inherit from each of those individual classes? As another alternative that you haven't mentioned yet, you could create a decorator to be applied to each method, which will inject it into the class at the time it is defined. The explicitness of the decorator solves your confusion problem of "why does this function use self". It creates a couple of new problems though: 1) reading the class won't tell you what methods it contains; and 2) making sure the class is fully constructed before it is used becomes tricky. --047d7bacb37ec25ff104f7bc57e6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Apr 23, 2014 5:01 PM, <tim.t= helion@gmail.com> wrote:
> I asked on IRC and it was sugested that I use multiple classes, howeve= r I see no logical way to separate a SubuserProgram object into multiple cl= asses.

You say you already have the methods logically separated int= o files. How about adding one abstract class per file, and then letting Sub= userProgram inherit from each of those individual classes?

As another alternative that you haven't mentioned yet, y= ou could create a decorator to be applied to each method, which will inject= it into the class at the time it is defined. The explicitness of the decor= ator solves your confusion problem of "why does this function use self= ". It creates a couple of new problems though: 1) reading the class wo= n't tell you what methods it contains; and 2) making sure the class is = fully constructed before it is used becomes tricky.

--047d7bacb37ec25ff104f7bc57e6--