Click here to Skip to main content
15,893,487 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: convert vb.net code to c# Pin
asmaqureshi821114-Aug-09 2:36
asmaqureshi821114-Aug-09 2:36 
QuestionFish bone diagram Pin
Amit Patel198513-Aug-09 6:47
Amit Patel198513-Aug-09 6:47 
AnswerRe: Fish bone diagram Pin
Abhijit Jana13-Aug-09 7:13
professionalAbhijit Jana13-Aug-09 7:13 
AnswerRe: Fish bone diagram Pin
Christian Graus13-Aug-09 14:33
protectorChristian Graus13-Aug-09 14:33 
GeneralRe: Fish bone diagram Pin
N a v a n e e t h13-Aug-09 15:44
N a v a n e e t h13-Aug-09 15:44 
QuestionPass dataview to javascript [modified] Pin
zeeShan anSari13-Aug-09 6:21
zeeShan anSari13-Aug-09 6:21 
AnswerRe: Pass dataview to javascript Pin
Abhishek Sur13-Aug-09 8:50
professionalAbhishek Sur13-Aug-09 8:50 
Questiona simple question about design patterns [modified] Pin
Mark Kamoski13-Aug-09 4:41
Mark Kamoski13-Aug-09 4:41 
All --

Please help.

I have a simple question about design patterns.

I need a quick design-pattern spot-check and thought a guru might have a minute.

I am not certain which design-patterns (if any) I am using or if I am using them correctly.


The short story...

I have a 1-to-1 mapping of DatabaseRow-to-Entity, where each Entity class just holds data.
I have a 1-to-1 mapping of EntityManager-to-Entity, where each EntityManager class just handles CRUD operations for its Entity.
If handling multiple Entity objects, they are collected into typed collections that are data-bindable.
I have a single DataContext that is used only by the EntityManager classes, and the DataContext knows how to connect to the database and run SQL-based CRUD operations

I think this uses TableModule + TableDataGateway + RowDataGateway + DataMapper.

What do you think?


The long story...

Here is what I do.

For each database table, I have one simple "Entity" class that maps directly to the table row. The Entity exposes each database column as a public property. The only logic in the Entity is validation logic, (such as IncomingValueForProperty1CannotExceedNCharacters, IncomingValueForProperty2CannotBeNull, etc), which simply throws an exception if there is a validation error. There is nothing else in the Entity class-- no SQL, no connection information, no database information, no SaveMethod, no UpdateMethod, nothing, etc. In short, the Entity just holds data. A sample name would be "AddressEntity".

Multiple Entity objects are collected in various says, such as a typed-collection, an array of objects, an EntitySet, or similar.

For each Entity, I have an "EntityManager" class. The sample name would be "AddressEntityManager". The EntityManager has methods like Create(AddressEntity targetEntity) and Retreive(object ID) and Update(AddressEntity targetEntity) and Delete(object ID). The Manager knows how to get data from the database based on an ID and return the data as a Entity. The Manager knows how to take an Entity passed to it and save the Entity to the database. Etc. The EntityManager uses the DataContext.

There is a single "DataContext" class that is used by all EntityManager classes. The DataContext class that knows how to connect to the database and conduct low-level CRUD, SQL-based operations.

This is very easy to implement and use. In particular, it is very clear to see who does what in terms of responsibility. The Entity holds data. EntityManager performs CRUD operations on an Entity. Need an Entity? Ask an EntityManager. Where is the data? Look in an Entity. Who does the work? The EntityManager. Who holds the data? The Entity. Need to do something to an Entity? Ask an EntityManager. It is transportable, in that it can be used on virtually any typical database-driven application. IMHO and IME.

A typical implementation is ASP.NET plus C# plus Linq-To-Sql (or Linq-To-Entities) plus SQL Server.

What pattern (or patterns) are expressed here?

I do have some ideas about which patterns are used. This way of working seems to have aspects of several patterns.

For "Domain Logic Patterns", it seems to have aspects of...
Table Module
http://www.martinfowler.com/eaaCatalog/tableModule.html[^]

For "Data Source Architectural Patterns", it seems to have aspects of...
Table Data Gateway
http://www.martinfowler.com/eaaCatalog/tableDataGateway.html[^]
Row Data Gateway
http://www.martinfowler.com/eaaCatalog/rowDataGateway.html[^]
Data Mapper
http://www.martinfowler.com/eaaCatalog/dataMapper.html[^]

However, I want to get your views on the matter, especially to help correct the design and improve it.

What do you think?

Please advise.

Thank you.

-- Mark Kamoski

modified on Thursday, August 13, 2009 1:27 PM

AnswerRe: a simple question about design patterns Pin
Jeremy Likness13-Aug-09 5:20
professionalJeremy Likness13-Aug-09 5:20 
GeneralRe: a simple question about design patterns Pin
Mark Kamoski13-Aug-09 5:35
Mark Kamoski13-Aug-09 5:35 
GeneralRe: a simple question about design patterns Pin
Jeremy Likness13-Aug-09 6:17
professionalJeremy Likness13-Aug-09 6:17 
GeneralRe: a simple question about design patterns Pin
N a v a n e e t h13-Aug-09 15:55
N a v a n e e t h13-Aug-09 15:55 
GeneralRe: a simple question about design patterns Pin
Mark Kamoski17-Aug-09 3:23
Mark Kamoski17-Aug-09 3:23 
AnswerRe: a simple question about design patterns Pin
Mark Kamoski17-Aug-09 3:26
Mark Kamoski17-Aug-09 3:26 
Questionglobal.asax redirect failing on windows 2008 box Pin
wolfbinary13-Aug-09 4:38
wolfbinary13-Aug-09 4:38 
AnswerRe: global.asax redirect failing on windows 2008 box Pin
Abhijit Jana13-Aug-09 19:17
professionalAbhijit Jana13-Aug-09 19:17 
GeneralRe: global.asax redirect failing on windows 2008 box Pin
wolfbinary21-Aug-09 10:32
wolfbinary21-Aug-09 10:32 
Questionstream reader Pin
lagan13-Aug-09 3:51
lagan13-Aug-09 3:51 
AnswerRe: stream reader Pin
DoctorMick13-Aug-09 6:11
DoctorMick13-Aug-09 6:11 
GeneralRe: stream reader Pin
lagan13-Aug-09 6:46
lagan13-Aug-09 6:46 
AnswerRe: stream reader Pin
N a v a n e e t h13-Aug-09 15:42
N a v a n e e t h13-Aug-09 15:42 
QuestionASP.NET is not authorized to access the requested resource. Pin
vandanaconedify13-Aug-09 3:15
vandanaconedify13-Aug-09 3:15 
AnswerRe: ASP.NET is not authorized to access the requested resource. Pin
Coding C#13-Aug-09 3:34
Coding C#13-Aug-09 3:34 
QuestionPlaceholder Pin
Ramkumar_S13-Aug-09 3:03
Ramkumar_S13-Aug-09 3:03 
AnswerRe: Placeholder Pin
Christian Graus13-Aug-09 14:42
protectorChristian Graus13-Aug-09 14:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.