Skip to main content
Context object

Name / classification

Context Object

Also known as

Context, Encapsulate Context

Intent

Decouple data from protocol-specific classes and store the scoped data in an object independent
of the underlying protocol technology.

Explanation

Real-world example


iluwatarAbout 2 minCreationalData access
Data Access Object

Intent

Object provides an abstract interface to some type of database or other persistence mechanism.

Explanation

Real world example

There's a set of customers that need to be persisted to database. Additionally we need the whole
set of CRUD (create/read/update/delete) operations so we can operate on customers easily.


iluwatarAbout 2 minArchitecturalData access
Identity Map

Intent

Ensures that each object gets loaded only once by keeping every loaded object in a map.
Looks up objects using the map when referring to them.

Explanation

Real world example

We are writing a program which the user may use to find the records of a given person in a database.


iluwatarAbout 3 minBehavioralPerformanceData access
Metadata Mapping

Intent

Holds details of object-relational mapping in the metadata.

Explanation

Real world example

Hibernate ORM Tool uses Metadata Mapping Pattern to specify the mapping between classes and tables either using XML or annotations in code.


iluwatarAbout 2 minArchitecturalData access
Optimistic Offline Lock

Intent

Provide an ability to avoid concurrent changes of one record in relational databases.

Explanation

Each transaction during object modifying checks equation of object's version before start of transaction
and before commit itself.

Real world example


iluwatarAbout 2 minConcurrencyData access
Private Class Data

Intent

Private Class Data design pattern seeks to reduce exposure of attributes by limiting their
visibility. It reduces the number of class attributes by encapsulating them in single Data object.

Explanation

Real world example

Imagine you are cooking a stew for your family for dinner. You want to prevent your family members
from consuming the stew by tasting it while you are cooking, otherwise there will be no more stew
for dinner later.


iluwatarAbout 2 minIdiomData access
Repository

Intent

Repository layer is added between the domain and data mapping layers to isolate domain objects from
details of the database access code and to minimize scattering and duplication of query code. The
Repository pattern is especially useful in systems where number of domain classes is large or heavy
querying is utilized.


iluwatarAbout 2 minArchitecturalData access
Resource Acquisition Is Initialization

Intent

Resource Acquisition Is Initialization pattern can be used to implement exception safe resource management.

Class diagram

Resource Acquisition Is Initialization

Applicability

Use the Resource Acquisition Is Initialization pattern when


iluwatarLess than 1 minuteIdiomData access
Serialized Entity Pattern

Intent

To easily persist Java objects to the database.

Explanation

Java serialization allow us to convert the object to a set of bytes. We can store these bytes into database as
BLOB(binary long objects) and read them at any time and reconstruct them into Java objects.


iluwatarAbout 2 minArchitecturalData access
Service Layer

Intent

Service Layer is an abstraction over domain logic. It defines application's boundary with a layer of services that
establishes a set of available operations and coordinates the application's response in each operation.

Explanation

Typically applications require different kinds of interfaces to the data they store and the logic they implement.
Despite their different purposes, these interfaces often need common interactions with the application to access and
manipulate its data and invoke its business logic. Encoding the logic of the interactions separately in each module
causes a lot of duplication. It's better to centralize building the business logic inside single Service Layer to avoid
these pitfalls.


iluwatarAbout 3 minArchitecturalData access
2