472,989 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Pattern for error checking easiest-first?

Heres the situation:

class AbstractThing():
def changeMe(self,blah):
if blah < 1:
raise MyException
self.blah = blah

class NetworkedThing(AbstractThing):
def changeMe(self,blah):
if blah self.getUpperLimitOverTheNetworkSlowly:
raise MyOtherException
AbstractThing.changeMe(self,blah)
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?

Aug 20 '07 #1
1 1118
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

Aug 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nicolla MacPherson | last post by:
Hi I'm a newbie and want to display a pattern that will increment with each line of display. I thought i might be able to count the rows and use that info to increment my display. I've got my...
1
by: Einar Høst | last post by:
Hi, I'm writing a data layer for an app my company is developing. I'm thinking about wrapping up the basic data access object in two decorator objects: one to provide error checking on...
4
by: FluffyCat | last post by:
New on November 29, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Command Pattern. Since you all enjoyed the Visitor Pattern so much yesterday, today I have the Command Pattern...
3
by: devikaapk | last post by:
can we use like keyword in if conditional checking?? i want to check a pattern exist in a var.. for eg: h_name = "Testing the proC from with pattern"; if h_name like 'Testing%proC%pattern'...
5
by: Alan Isaac | last post by:
I have two questions about the "observer pattern" in Python. This is question #1. (I'll put the other is a separate post.) Here is a standard example of the observer pattern in Python:
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.