Programming Theory
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesProgramming Theory

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 13th, 2009, 11:00 AM
mkamoski mkamoski is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 1 mkamoski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 24 sec
Reputation Power: 0
A simple question about design patterns

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. 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
(Reference: Martin Fowler)

For "Data Source Architectural Patterns", it seems to have aspects of...
Table Data Gateway
(Reference: Martin Fowler)
Row Data Gateway
(Reference: Martin Fowler)
Data Mapper
(Reference: Martin Fowler)

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

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesProgramming Theory > A simple question about design patterns


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek