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’re prone to shortcuts

In a conventional layered architecture, the only global rule is that from a certain layer, we can only access components in the same layer or a layer below. There may be other rules that a development team has agreed upon and some of them might even be enforced by tooling, but the layered architecture style itself does not impose those rules on us.

So, if we need access to a certain component in a layer above ours, we can just push the component down a layer and we’re allowed to access it. Problem solved. Doing this once may be OK. But doing it once opens the door for doing it a second time. And if someone else was allowed to do it, so am I, right?

I’m not saying that as developers, we take such shortcuts lightly. But if there is an option to do something, someone will do it, especially in combination with a looming deadline. And if something has been done before, the likelihood of someone doing it again will increase drastically. This is a psychological effect called the Broken Windows Theory – more on this in Chapter 11, Taking Shortcuts Consciously.

Figure 2.3 – Since any layer may access everything in the persistence layer, it tends to grow fat over time

Figure 2.3 – Since any layer may access everything in the persistence layer, it tends to grow fat over time

Over years of development and maintenance of a software project, the persistence layer may very well end up like in Figure 2.3.

The persistence layer (or, in more generic terms, the bottom-most layer) will grow fat as we push components down through the layers. Perfect candidates for this are helper or utility components since they don’t seem to belong to any specific layer.

So, if we want to disable shortcut mode for our architecture, layers are not the best option, at least not without enforcing some kind of additional architecture rules. And by enforcing, I don’t mean a senior developer doing code reviews, but automatically enforced rules that make the build fail when they’re broken.

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