Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How TableData gateway differs from Rowdata Gataway?.. need clarification

I have recently been reading about,TableData Gateway and RowData Gateway.According to "Patterns of Enterprise Application Architecture" RDG deals with one record at a time and TDG deals with a whole table.But both these patterns look very similar,they encapsulate SQL queries and either return a single record or many records in a recordset based on the queries we make.I cannot really figure out when to prefer TDG for RDG.It would be very helpful to clarify the difference with some explaination.According to Martin Fowler TDG is the same as RDG when it returns one record.But we can also use RDG for multiple records also!then why use TDG. Any help will be appreciated. Thank You.

like image 654
Alex Avatar asked Jul 22 '11 13:07

Alex


1 Answers

Row Data Gateway encapsulates access to a row in the DB, whereas Table Data Gateway encapsulates access at the table level, and it doesn't seem to me that one is a degenerate form of the other at all.

While Table Data Gateway has find methods that return RecordSets, with Row Data Gateway, you need a separate Finder class that returns one gateway class per row.

Whether you use either and which you use are complex decisions tied in with your choices of which other patterns you're using.

From his discussions in the "When to Use It" sections about both patterns, if using the Domain Model pattern, he would prefer using Active Record over either. Both of these gateway patterns are sensible to use in combination with Transaction Script.

Table Data Gateway is simpler, so if it does what you need it might be the right choice.

You wouldn't likely ever use both of these patterns in a single application.

like image 90
Don Roby Avatar answered Nov 02 '22 10:11

Don Roby