In “The Matrix” movie series, there was a character called “The Architect” who built the eponymous computer simulation.

It’s fitting since the ideas for applying patterns to programming came from the world of architecture. In 1977 Christopher Alexander’s book “A Pattern Language” influenced the software development world.

In 1987, Ward Cunningham and Kent Beck started what would eventually become a book published in 1993. The book highlighted how making reusable patterns or templates could make development better.

How have things developed in 30-odd years of software design patterns? Enter: the data access object (DAO) pattern.

What is a DAO pattern, and how can you use it in your next project? Keep reading to find out.

What Is a Software Design Pattern?

Almost every programming language now uses software design patterns in almost every application. Even if you didn’t knowingly do it, you’ve used them.

If you’re building a blockchain biometrics platform or making a button on a JavaScript applet for a website, you’re following patterns. They solve problems for designing a system or application that the language doesn’t have built-in support for.

Relationships often form between objects and classes in object-oriented design patterns. Using the software design pattern for an object-oriented language often doesn’t suit other types of languages.

Instead, they need their own software design patterns based on recurring themes within them.

DAO Patterns

Data access object (DAO) patterns separate high-level business services from low-level data. Different components of a DAO pattern are:

  • TransferObject
  • DataSource
  • DataAccessObject
  • BusinessObject

The DataAccessObject is the most important part of this type of pattern, though all are necessary at some level. This object will abstract the data access implementation that the BusinessObject uses to get access to data source(s).

TransferObject is an object used as a carrier of data. The DataAccessObject could use it to get data returned to the client. It could also get data from the client or updates in the data source(s).

The BusinessObject makes up the data client. It needs access to the data source(s) to get and sure data. In Java, it’s an entity bean, or session bean, or other Java object that accesses data source(s).

Speaking of data sources, DataSource could represent a database like an XML repository, flat file system, OODBMS, or RDBMS. In essence, any structured system service or repo will do.

DAO pattern has the advantage of using DAOs is that it’s simple. it takes two important parts of applications that are expected to work in an independent matter, without knowledge of the other part.

Also, if you need to change persistence mechanisms, you only need to change the DAO layer. In other words, you don’t have to change all the places in the logic that uses the DAO.

It has the disadvantage of having abstraction that’s leaky or inverted. There could also end up being quite a bit of unwanted code duplication.

Data Access Objects: A Pattern to Live By

Like many other parts of life, a DAO pattern helps us to not “reinvent the wheel” every time we go to do a task. In the end, it’s a standard way to solve a common problem.

If you have more common problems to solve, make sure to access your data source regularly. We have the advice and information you need to stay ahead in your career, business news, and tech. Keep browsing to find out!

(Visited 16 times, 1 visits today)