Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Proper way to stop New() execution
Message
 
À
30/10/2006 21:25:05
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01165405
Message ID:
01165951
Vues:
13
>>If you have code that needs to exit during construction you probably have a design flaw <s>...
>
>Well, the New() event of the object defines a lot of properties. But, to define one of those properties, I need to execute a SQL command. In one particular circumstance, it may be that the SQL command would return no record. If that is the case, I need to redirect to another page with a message. But, doing a redirect inside a New() constructor will not work. So, what I do is that I initialize a property lStop to True and use that later on.
>
>What would you recommend to enhance that design?

If you have 'application' level code you probably shouldn't run that code in in the constructor. A constructor should just bring up the object with as few dependencies as possible. Instead consider creating an Initialize() method or something like that that you can externally to set up your connection etc. You can return true or false from that and you can manage that in your application code more easily.

Throwing exceptions will give you that same functionality but I personally think that object instantiation should always work unless there's truly an exceptional failure.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform