General Refactorings

Separate Data Access Code

Data access code is embedded directly within a class that has other unrelated responsibilities.

Extract the data access code into a new class and move the new class logically and/or physically closer to the Data Source.

Figure 5.21. Separate Data Access Code

Motivation

Create cleaner abstractions, increase cohesion, and reduce coupling, thus improving modularity and reusability.

Mechanics
  • Identify and extract the data access logic from the controller object.

    • Use Extract Class [Fowler] to create a new class and move data access code from the original class into the new Data Access Object (DAO) class. ...

Get Core J2EE™ Patterns: Best Practices and Design Strategies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.