Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

.Net Design Patterns?

Hello,
We recently launched a small (3 developers) laboratory managment project and chose .Net as our development environment. As technical lead I took the opportunity to begin my usage of various design patterns I have become smitten with: a mixture of Martin Fowler's Analysis Patterns as well as the Domain Neutral Component (DNC). So far, I have been enjoying things.

I was wondering what other .Netters experience has been with design patterns and what particular patterns they have found useful for their work? I'm particularly interested in strategies for layer separation (presentation-domain-dbase).

Relevent links:
Martin Fowler's Patterns of Enterprise Application Architecture: http://www.martinfowler.com/isa/
In particular see Fowler's discussion of the Table Module: http://www.martinfowler.com/isa/tableModule.html

DNC stuff can mostly be found at The Coad Letter (Peter Coad's stuff) http://thecoadletter.com
Here is a (fat) link to a PDF doc of chapter 1 of the DNC bible "Java Modeling in Color with UML" http://thecoadletter.com

DOuglass Turner
Wednesday, September 25, 2002

The pattern I chose? A N-Tiered pattern, of course. Here are the layers

ClientWinForms
It contains all the interface(forms), and all client-side operations(reporting, etc)

BusinessRules
For each form in ClientWinForms, I have a class here. It has a method for each thing ClientWinForms need to do with the data. For example, I have those methods: InsertCustommer, UpdateCustommer and DeleteCustommer. The constructor of such classes takes a username/password, and then I get the authorisations of that user(I store it in a structure). Each method of that class verify if the user is authorized to do the operation. In this layer, I do validation and everything not related to the interface, and not related to the database itself. Only data manipulation. This class is either exposed via remoting(multi-users), either instanciated as a normal class(single-user). Almost forgot something important... I usually pass data between ClientWinForms and BusinessRules in typed datasets.

DataAccess
This layer contains code related to database manipulations. This will create the SqlConnection, SqlCommand and do all the necessary operations. There is no validation here. All methods of all classes of this layer are shared (or static), and BusinessRules is the only layer who can access it.

I could add a layer later: ClientWeb, wich would contain a web interface for some parts of the program. It would use the same business rules layer.

I don't really know what kind of project you're doing, so I don't know if this pattern would work for you. At least, it works flawlessly for me :)  and I don't see what I can't do with it.

Etienne Charland
Wednesday, September 25, 2002

Yup...that's pretty much how we're doing it too.

Richard Caetano
Thursday, September 26, 2002

Hello,

Microsoft made a free tool called FxCop wich is a code analysis tool and you can check your code against some guidlines with it. These guidlines are implemented by microsoft but I think you can implement your own rules as well!

http://www.gotdotnet.com/team/libraries/

Br
Cris

Krisztian Gyuris
Thursday, September 26, 2002

One of the patterns I have found useful is the enterprise patter - data mapper: http://www.martinfowler.com/isa/databaseMapper.html

If you've used EJBs then this pattern should stand out, it's the same way beans are mapped to DB fields. It's flexible though so you can map an Class fields/properties across multiple tables. I usually create a "store" that I use to load and save types using this pattern.


Another pattern I've found useful is metaData mapping or a variation of it: http://www.martinfowler.com/isa/metadataMapping.html

I've used this pattern in the past to map http request fields to class fields. I usually create a read method that reads the http field names and looks for their equivalent class property counterparts using reflection then sets them. So If I have a foo object with a foo.Color property it will map the color http field to it. This is an old Java trick (and probably before that suign C/C++/whatever)

Ian Stallings
Thursday, September 26, 2002

*  Recent Topics

*  Fog Creek Home