We could in theory skip the whole database part and, by ourselves:
In reality, databases already do that: they either have to store data in memory or on the file system.
That's one of the reasons why we use databases: they already handle those problems for us.
Every database should ensure the following four properties for its transactions:
Separate concerns as well as possible.
Allow the replacement of some parts (display technology, database, etc) without affecting the whole system.
Components within the layered architecture pattern are organized into horizontal layers, each layer performing a specific role within the application (e.g., presentation or business logic).
Dependencies should only flow from the upper layers to lower levels.
Dependencies should only exist between adjacent layers.
Not really used anymore in its original form, where the gateway receives primitive types as input.
An object that acts as a Gateway to a database table. One instance handles all the rows in the table.
Probably the most viable of the four patterns.
A layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself.
Typically, data is stored nowadays in specialized plain classes (which only have fields, constructors, getters, setters) = "POJO".
To persist the instances of these classes, a (usually singleton per table) DAO is used. The DAO is an improved version of the Data Mapper and the Table Data Gateway patterns.
An even higher abstraction is a repository, which exposes a collection-like interface for manipulating entities.
A repository may work with multiple tables (for example a parent table and more child tables) and may use underneath one or more DAOs.
Defines an application's boundary with a layer of services that establishes a set of available operations and coordinates the application's response in each operation.
This fits perfectly with the layered architecture approach: we will define a layer which contains only "services" encapsulating the business logic.
Transaction script bundles all the logic for a business transaction within a single class.
Table module encapsulates all the logic related to a given database table in a single class.
Translated into "services":
It is a creational design pattern in which object creation is delegated to a specialized factory. It allows to easily switch between the concrete implementation of the objects instantiated.