Home

On 20 ago, 18:01, jquinn+goo...@cs.oberlin.edu wrote:

> The problem is that code like this does error checking backwards. A
> call to NetworkedThing.changeMe will first do a slow error check and
> then a fast one. Obviously there are various ways to get around this -
> either have the subclass explicitly ask the superclass to error check
> first, or vice totally versa. Is there some accepted pattern/idiom for
> handling this issue?

What about this:

class AbstractThing():
def changeMe(self,blah):
self.verify_blah(blah)
self.blah = blah

def verify_blah(self, blah):
if blah < 1:
raise MyException

class NetworkedThing(AbstractThing):
def verify_blah(self, blah):
AbstractThing.verify_blah(blah)
if blah > self.getUpperLimitOverTheNetworkSlowly:
raise MyOtherException

That is, it's the verify step that is overriden/enhanced, not the
changeMe method that stays the same.

--
Gabriel Genellina

previous
next

Re: Urgent!!! UPGRADE METHODOLOGY
Re: Requirement at Yahoo [spam]
Re: Google and Python
Re: no response from allocator
Re: comma overload semantics
Fundacja Hobbit
Kidprotect
Nasze Dzieci
Krwinka
Mimo Wszystko