Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Class with static members and methods
Message
 
À
18/01/2005 10:12:35
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00977883
Message ID:
00978103
Vues:
46
Bonnie,
Thank you for your reply and your comments and thoughts. I have reflected on static methods since I posted this thread and I have come to the conclusion that I will have to justify (i.e. think really hard about why I choose the method to be static) when I create static methods.
My example in the original post works great beeing only static members, but I have encoutered a drawback: if I want to add several configuration files to my application I have to rebuild my class so that I can create an instance, but I will deal with that another day because I have no need for multiple configuration files at this point.

I have started to think about static members as a global member in VFP. Would this be a correct comparison? (I also remember disliking using global members in VFP because of all the trouble it could get me into, but I guess in C# it is better because of the protection namespaces provide.)

Again thank you for your reply, I value your response.

Sincerely,
Einar

>Einar,
>
>>1. Is there a penalty to create a class like this compared to creating a class with non-static members where I have to create an instance of the class in order to use it?
>
>Static properties and methods are handy sometimes. The only "penalty" I can see is that it remains in memory, so going overboard is probably not good ... but then again, only one copy of these static members ever exist, no matter how many instances of the class are created. So, if it's something that gets used from a lot of different places in your app, it's a good candidate for using static members.
>
>Your example is a good. Another example: we make use of statics in several codes datasets that we use throughout our app. Once the dataset is filled, it's members are available throughout the app and are particularly useful for the datasource to ComboBox's. They are Typed DataSets, so we have additional static methods defined in the class.
>
>>2. After I run the Initialize() method how long will the dataset dsOptions be in memory?<
>
>Until your app closes.
>
>>3. I added a constructor, with a messagebox telling me that I was in the constructor, to the class. I thought the constructor would be executed the first time a static method in the class was executed, but the constructor was never executed unless I created an instance of the class (but there was no benefit to creating an instance).<
>
>Well, no, there's no benefit to creating an instance unless you have code that needs initializing. In your case, you created an Initialize method. You could have just as easily put that code in the constructor and instantiated the class only once (like when your app starts). It would have amounted to the same thing.
>
>~~Bonnie
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform