A gateway encapsulates the semantic gap between the object-oriented domain layer and the relation-oriented persistence layer. More specifically, it encapsulates and centralizes the application's SQL:
More generally, a gateway can be anything that hides access to a remote server or a complex library.
For each persistent class in the domain layer we assume there is a corresponding table (virtual or base) in the database and we introduce a corresponding gateway:
Here's an object diagram showing the table schemas:
Here's a simple Gateway class:
The SQL would be created in the Gateway subclasses.