From the course: PHP: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Introducing the table data gateway pattern

Introducing the table data gateway pattern - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

Introducing the table data gateway pattern

- Now let's talk about the Table Data Gateway, which is the second data access pattern we'll cover. As you've been watching these videos, you may wonder why we're covering this one after already discussing active record. After all, they're both ways to interact with the database. Do we really need both? In short, yes. Active record was built on the idea of interacting with individual database rows, embedding that logic directly into your domain logic. While that works in many scenarios, it can get messy blending those types of logic. And that's the fundamental problem. One of the concepts of good, object-oriented design is single responsibility. Which means that an object should have one, and only one purpose, and stick to that. Once you start embedding your database access into your domain logic, you can easily end up with these massive objects that are challenging to maintain. Even worse, with poorly designed objects, you can end up with the database logic spread all over the place,…

Contents