Thursday, January 6, 2011

Table Data Gateway Design Pattern

Many developers are not ware of the existence of such a design pattern. This pattern is used to introduce a layer between the Business and the Data. Not all the Java developers are that good in writing SQL queries. A DBA will know the best way of how to write a SQL query and if all the queries are written by a single group of DBA's the they will be able to identify ways to tune the database to get maximum efficiency. SO it’s always good not to mix up the sql with the Java Code. The Table Data Gateway Design Pattern serves this purpose where we can put in all the code to access database like insert, update, delete, create and retrieval operations. This object will serve as the gateway for the Business logic to do all sorts of Database application. For every table in the database this pattern introduces a Gateway object through which all the table manipulations can be done. The original pattern recommends to send all the details of a row as parameters to the method in the Gateway class.
This may not be the best way to build a scalable object. So some developers recommend using the Object with all the parameters in it and then send that object to the Gateway Object to persist it. Having done this in case there happens to be a requirement to add a new column then we can just make a change to the internal logic instead of adding overloaded methods and getting older methods deprecated.
Related Posts Plugin for WordPress, Blogger...