It's a mix and mash thing, when you crate a web application you may be using ASP.NET but exactly how many technologies are you actually using? What patterns, technique, ... Well it's mix and mash...
So here is the next step of the evolution towards a web application, the data layer. This is no way a "standard", it's more to make life easier for first myself, second my co-workers.
These are my 13 guidelines:
- Structure your Namespaces, make it logical, readable. Take your queues for the Microsoft Framework. Keep it logical, data related and simple.
- Make use of the tools you have to make you code logical and flowing. Make use "regions", name your classes as close as possible to your data table names. It makes it simpler to read and debug.
- Keep the methods sweet and short, do not be ashamed to have 1 liners.
- Never have conditions within conditions, it meses code and makes it unreadable. I always say a developer should be able to read code like he reads a good novel.
- Name your methods logically with descriptive names.
- If you are going to use collections, generics are a good idea. In fact, take it further, have a look at Wintellect PowerCollections, I can't get enough of it.
- In your properties, do some data validation, catch the error before it happens. Maybe start using Microsoft's Validation Block from the forthcoming Enterprise Library 3.0
- Why not use Microsoft's Enterprise Library for data access, caching, encryption, and more...
- Have standard methods such as Save, Delete, Populate.
- Always have an empty constructor. And always have a constructor with a default population scheme.
- Have an initialize method that gets called for all constructors to validate the class setting and access.
- Comment and document your code !!!
- Make use of abstract classes (The examples are not abstract classes)
You can download the examples from here:
C# /
VB.NET
Thank you Shaun Farrell for the C# version.