overwriting method in baseclass

Discussion in 'Python' started by Harald Massa, Feb 7, 2005.

  1. Harald Massa

    Harald Massa Guest

    Hello!

    I am using a library (= code of so else) within Python. Somewhere in this
    library there is:

    class foo:
    def baa(self, parameters):
    print "something"
    self.baazanan(some other parameters)


    class mirbo(foo):
    def baazanan(self, lalala):
    print "heylo tada"

    class fujiko(foo):
    def baazanan(self, ltara):
    print "sing a song with me"


    .....


    now I want to change the common baa-method. so that

    def baa(self, parameters):
    print "soemthing special"
    self.baazanan(some other parameters)

    Of course, I use a Python- and GPL-Licence compatible library, I can
    change the source of foo, and use my changed library.

    But someday, it happened before, there will be an update by the publisher
    to that library.... and I have to do all again.

    So, what is the most elegant solution to administer these changes?

    Harald
     
    Harald Massa, Feb 7, 2005
    #1
    1. Advertising

  2. Harald Massa wrote:
    > Hello!
    >
    > I am using a library (= code of so else) within Python. Somewhere in this
    > library there is:
    >
    > class foo:
    > def baa(self, parameters):
    > print "something"
    > self.baazanan(some other parameters)
    >
    >
    > class mirbo(foo):
    > def baazanan(self, lalala):
    > print "heylo tada"
    >
    > class fujiko(foo):
    > def baazanan(self, ltara):
    > print "sing a song with me"
    >
    >
    > ....
    >
    >
    > now I want to change the common baa-method. so that
    >
    > def baa(self, parameters):
    > print "soemthing special"
    > self.baazanan(some other parameters)
    >
    > Of course, I use a Python- and GPL-Licence compatible library, I can
    > change the source of foo, and use my changed library.
    >
    > But someday, it happened before, there will be an update by the publisher
    > to that library.... and I have to do all again.
    >
    > So, what is the most elegant solution to administer these changes?


    Given these classes:

    py> class foo:
    .... def baa(self):
    .... print "something"
    .... self.baazanan()
    ....
    py> class mirbo(foo):
    .... def baazanan(self):
    .... print "heylo tada"
    ....
    py> class fujiko(foo):
    .... def baazanan(self):
    .... print "sing a song with me"
    ....

    You should be able to redefine the method and assign it to the foo class:

    py> def new_baa(self):
    .... print "soemthing special"
    .... self.baazanan()
    ....
    py> foo.baa = new_baa

    Then any instances created after this assignment should use the new baa
    method you defined:

    py> mirbo().baa()
    soemthing special
    heylo tada
    py> fujiko().baa()
    soemthing special
    sing a song with me

    You also might bring up this point to the maintainer of the library --
    if they know your intents, they can make this easier for you...

    STeVe
     
    Steven Bethard, Feb 7, 2005
    #2
    1. Advertising

  3. Harald Massa wrote:
    > Hello!
    >
    > I am using a library (= code of so else) within Python. Somewhere in this
    > library there is:
    >

    (snip)
    >
    >
    > now I want to change the common baa-method. so that
    >

    (snip)

    > Of course, I use a Python- and GPL-Licence compatible library, I can
    > change the source of foo, and use my changed library.
    >
    > But someday, it happened before, there will be an update by the publisher
    > to that library.... and I have to do all again.
    >
    > So, what is the most elegant solution to administer these changes?


    <ot>
    Use a version control system (svn is quite fine...).
    </ot>

    --
    bruno desthuilliers
    ruby -e "print ''.split('@').collect{|p|
    p.split('.').collect{|w| w.reverse}.join('.')}.join('@')"
    --
     
    bruno modulix, Feb 7, 2005
    #3
  4. Harald Massa

    Harald Massa Guest

    bruno modulix <> wrote in
    >
    >> So, what is the most elegant solution to administer these changes?

    >
    > <ot>
    > Use a version control system (svn is quite fine...).
    > </ot>


    Thanks for that recommendation, I really do use subversion for some time.
    But how can I use it to solve this problem? I do changes to the common
    baseclass which is OUTSIDE my development. I quite correctly assume that
    the developers of the classlib also use Subversion, alas, having no public
    access.

    So HOW can SVN be of any use for THIS prob?

    Harald
     
    Harald Massa, Feb 7, 2005
    #4
  5. In <Xns95F6BFBF27210cpl19ghumspamgourmet@195.20.224.116>, Harald Massa
    wrote:

    > Thanks for that recommendation, I really do use subversion for some time.
    > But how can I use it to solve this problem? I do changes to the common
    > baseclass which is OUTSIDE my development. I quite correctly assume that
    > the developers of the classlib also use Subversion, alas, having no public
    > access.
    >
    > So HOW can SVN be of any use for THIS prob?


    Take a look at the Subversion documentation (the "book") and search for
    `Vendor branches`.

    First paragraph of that section:

    As is especially the case when developing software, the data that you
    maintain under version control is often closely related to, or perhaps
    dependent upon, someone else's data. Generally, the needs of your
    project will dictate that you stay as up-to-date as possible with the
    data provided by that external entity without sacrificing the stability
    of your own project. [...]

    The section deals specifically with the situation how to manage 3rd party
    source code with subversion which you want to update from time to time and
    even apply some modifications.

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Feb 8, 2005
    #5
  6. Harald Massa

    Harald Massa Guest

    marc,

    >> So HOW can SVN be of any use for THIS prob?

    >
    > Take a look at the Subversion documentation (the "book") and search
    > for `Vendor branches`.
    >

    [...]
    > The section deals specifically with the situation how to manage 3rd
    > party source code with subversion which you want to update from time
    > to time and even apply some modifications.


    thank you very much for pointing this out! I did not even dare to hope to
    find sth. of this kind with a rcs for MY software.

    So I did not even start searching.

    Thank you,

    Harald
     
    Harald Massa, Feb 9, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. verbatime
    Replies:
    7
    Views:
    350
    John Harrison
    Mar 4, 2004
  2. Steven T. Hatton
    Replies:
    2
    Views:
    417
    tom_usenet
    Aug 16, 2004
  3. andy
    Replies:
    2
    Views:
    345
    Dietmar Kuehl
    Mar 17, 2005
  4. Edward C. Jones

    Problem with __str__ if baseclass is list

    Edward C. Jones, Nov 12, 2005, in forum: Python
    Replies:
    1
    Views:
    303
    Serge Orlov
    Nov 13, 2005
  5. Jaco Naude
    Replies:
    8
    Views:
    677
    Paul N
    Sep 28, 2010
Loading...

Share This Page