Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Get Your Hands Dirty on Clean Architecture

You're reading from   Get Your Hands Dirty on Clean Architecture Build 'clean' applications with code examples in Java

Arrow left icon
Product type Paperback
Published in Jul 2023
Publisher Packt
ISBN-13 9781805128373
Length 168 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Tom Hombergs Tom Hombergs
Author Profile Icon Tom Hombergs
Tom Hombergs
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Chapter 1: Maintainability 2. Chapter 2: What’s Wrong with Layers? FREE CHAPTER 3. Chapter 3: Inverting Dependencies 4. Chapter 4: Organizing Code 5. Chapter 5: Implementing a Use Case 6. Chapter 6: Implementing a Web Adapter 7. Chapter 7: Implementing a Persistence Adapter 8. Chapter 8: Testing Architecture Elements 9. Chapter 9: Mapping between Boundaries 10. Chapter 10: Assembling the Application 11. Chapter 11: Taking Shortcuts Consciously 12. Chapter 12: Enforcing Architecture Boundaries 13. Chapter 13: Managing Multiple Bounded Contexts 14. Chapter 14: A Component-Based Approach to Software Architecture 15. Chapter 15: Deciding on an Architecture Style 16. Index 17. Other Books You May Enjoy

They hide the use cases

As developers, we like to create new code that implements shiny new use cases. But we usually spend much more time changing existing code than we do creating new code. This is not only true for those dreaded legacy projects in which we’re working on a decades-old code base but also for a hot new greenfield project after the initial use cases have been implemented.

Since we’re so often searching for the right place to add or change functionality, our architecture should help us to quickly navigate the code base. How does a layered architecture hold up in this regard?

As already discussed previously, in a layered architecture, it easily happens that domain logic is scattered throughout the layers. It may exist in the web layer if we’re skipping the domain logic for an “easy” use case. And it may exist in the persistence layer if we have pushed a certain component down so it can be accessed from both the domain and persistence layers. This already makes finding the right spot to add new functionality hard.

But there’s more. A layered architecture does not impose rules on the “width” of domain services. Over time, this often leads to very broad services that serve multiple use cases (see Figure 2.5).

Figure 2.5 – “Broad” services make it hard to find a certain use case within the code base

Figure 2.5 – “Broad” services make it hard to find a certain use case within the code base

A broad service has many dependencies on the persistence layer and many components in the web layer depend on it. This not only makes the service hard to test but also makes it hard for us to find the code responsible for the use case we want to work on.

How much easier would it be if we had highly specialized, narrow domain services that each serve a single use case? Instead of searching for the user registration use case in UserService, we would just open up RegisterUserService and start hacking away.

You have been reading a chapter from
Get Your Hands Dirty on Clean Architecture - Second Edition
Published in: Jul 2023
Publisher: Packt
ISBN-13: 9781805128373
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime