Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
STATIC (shared) versus non static
Message
De
14/07/2014 01:41:09
 
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01603606
Message ID:
01603624
Vues:
51
>I wonder what the best practice would be when it comes to declare classes (and more importantly methods) static. I have found that in most cases pundits declare non static classes and methods where it would be perfectly workable to have them static.
>
>The way I see it is that static is easier to test no?

In addition to the rest of the replies

Static means not related or specific to an instance

eg: a Person class

Instance properties/methods would be Name, BirthDate, address, etc since that are 'things' that belong to a specific Person ( or instance)
We do not have the same name, do we ?
A method like CalculateAge() or GetAge() would not be static since it would use the (instance) property DateOfBirth

CalculateAge() could be static when it would accept dateOfBirth as a parameter

Static means applicable to any instance, ie not needing instance properties

Static does not necessarily mean that it is easier to test - the only difference is that you don't have to instantiate the class before using it
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform