Posts

Showing posts with the label Data Source Architectural Patterns

Data Mapper Pattern

Image
This pattern belongs to  Data Source Architectural Patterns  Catalog and this Catalog belongs to  Patterns of Enterprise Application Architecture . Intent A layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself. Mapper means an object that sets up a communication between two independent objects. Applicability Use the Data Mapper in any of the following situations when you want to decouple data objects from DB access layer when you want to write multiple data retrieval/persistence implementations Explanation The Data Mapper is a layer of software that separates the in-memory objects from the database. Its responsibility is to transfer data between the two and also to isolate them from each other.  With Data Mapper the in-memory objects needn't know even that there's a database present; they need no SQL interface code, and certainly no knowledge of the database schema.  How...

Active Record Pattern

Image
This pattern belongs to  Data Source Architectural Patterns  Catalog and this Catalog belongs to  Patterns of Enterprise Application Architecture . Intent An object that wraps a row in a database table or view, encapsulates the database access and adds domain logic on that data. Explanation Each Active Record is responsible for saving and loading to the database and also for any domain logic that acts on the data. An object carries both data and behavior. Much of this data is persistent and needs to be stored in a database.  Active Record uses the most obvious approach, putting data access logic in the domain object. This way all people know how to read and write their data to and from the database. The principal difference between  Row Data Gateway and Active Pattern is  Row Data Gateway pattern does not contain domain logic methods and Active Pattern object contains  domain logic methods. As an example, imagine we needed some...

Row Data Gateway Pattern

Image
This pattern belongs to  Data Source Architectural Patterns  Catalog and this Catalog belongs to  Patterns of Enterprise Application Architecture . Intent An object that acts as a Gateway to a single record in a data source. There is one instance per row. Here  Gateway means  an object that encapsulates access to an external system or resource. This object does not contain domain logic methods. If you introduce other methods (in particular domain logic) the object becomes an Active Record Pattern. How It Works A Row Data Gateway acts as an object that exactly mimics a single record, such as one database row.  For example, Person class has an id,firstName and lastName fields.   public class Person { private int id; private String firstName; private String lastName; // Getter and Setter methods } Person table for Person Java class. id firstName lastName 1 Ramesh Fadatare This pattern holds the data about a row so t...