Monday, November 25, 2013

Using Methods and Classes

Generally classes have two purposes:


They containt Data - one or more Field/Property - and functions to work with the Data. For some containing the data is the bigger issue (a Person class with little in the way of Functions)*. For others using the Data is more important (a DBConnection is pretty worthless unless you use the Connection string to actually open the Conenction to the DB. The same way a DBCommand's Query, Paramters and Connection are worthless unless you execute it).


The second rarer purpose is a Function Collection. The rule in .NET is that "every Function/Method must belong to a class, no exceptions". These classes are almost exclusively static and have exclusively static functions. They might have some constant public fields too (and constant includes static). Math is a very good example of a Functions collection class. As are classes like Int32, Float, Double and the like (all they do is provide Functions to manipulate the Value Types).


*Note that this role might also be fullfilled by Structs. There are somewhat lightweighter (they count as Value Types for overhead), but they are also harder to use (since they are value types you have to remmber to use call by reference while they look like a class).




Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.


No comments:

Post a Comment