views:

375

answers:

5

I am developing an app in ASP.NET C# and came across the following scenario:

  1. I will have to create some maintenance screens for different entities (tables)
  2. Those entities will basically have the same behaviour within the UI: Search, GetById, Save, Create and GetAll
  3. The entities may have different structure i.e. different properties (fields)

As I am talking about 20 plus admin screens, which design pattern I could take advantage of in order to minimize the amount of code I will have to write?

I though of the bridge pattern but I am a little confused on how to implement it ...

A little bit of the technology background I am using:

  1. ASP.NET classic (n-tier)
  2. LINQ to SQL and DAO objects
  3. SQL Server 2005
+4  A: 

For a set of admin screens that are just doing CRUD (Create, Read, Update, Delete) operations and with little in the way of business logic, I'd be quite tempted to more or less eschew design patterns and take a look at asp.net dynamic data. This is especially true if you want to minimise the amount of code you want to write.

Steve Willcock
You beat me to it :)
Timothy Khouri
I understand that but this is not part of our framework, therefore cannot be used!
afgallo
Ok, in that case, I would look at the patterns already used in your 'framework' and use a similar pattern. If there is nothing similar you might want to look at a Generic repository pattern - e.g. http://aleris.wordpress.com/2009/04/17/implementing-a-simple-generic-repository-with-linqtosql/
Steve Willcock
@Steve ... that might be what I am looking for ... I will give this a try to see if that fits in my requirements ... I'll post the results later on ...tks ...
afgallo
+2  A: 

This is not a design pattern... but I would strongly suggest using Dynamic Data. Jonathan Carter has some great articles about it: http://lostintangent.com/index.php?s=dynamic+data

Timothy Khouri
I understand that but this is not part of our framework, therefore cannot be used!
afgallo
+1  A: 

If you're really just doing some basic stuff like this: Search, GetById, Save, Create and GetAll, I would recommend you use repositories. If done wrong repositories can get really bad and nasty, but if you're really primarily limited to this set of operations you've basically described a repository with that set of operations.

You'll want to look at ways in which you can extract the extra logic for example of searching so that you're not creating duplicate logic.

Repositories are nice and testable as long as you make sure not to let them get out of control. I give you this warning only because I've seen far too many people create monster classes out of repositories.

The repositories work with your objects. They are basically the intermediary which handles the persistence of your data. This abstraction allows you to hide from the rest of your code how you're persisting your data. In this case the implementations of your repositories will be using LinqToSql as I believe that is what you said you were using.

There are plenty of resources explaining the repository pattern.

Brendan Enrick
Sorry but what sort of repository are you talking about? Is this repository pattern a creational, structural or behavioral pattern? I'm looking for something that will handle to whole process, from the client request to the actual database query using Linq2Sql ....
afgallo
I would say it is behavioral. What you need to keep in mind is that you need some sort of separation between your layers. The repository acts as this separation by keeping the UI from knowing that you're using Linq2Sql.
Brendan Enrick
A: 

What you want is not a design pattern. You are looking for an ORM with scaffolding. I have used and highly recommend SubSonic - http://subsonicproject.com. You can read about its scaffolding features here: http://subsonicproject.com/web-forms-controls/the-scaffold/

Naren
A: 

Answered as per Steve Willcock comments. Thanks!

afgallo