43 lines
1.3 KiB
Markdown
43 lines
1.3 KiB
Markdown
---
|
|
title: Do you separate your logic?
|
|
date: 2024-06-11
|
|
permalink: daily/2024/06/11/do-you-separate-your-logic
|
|
tags:
|
|
- software-development
|
|
- clean-code
|
|
cta: ~
|
|
snippet: |
|
|
Do you separate your logic into different categories?
|
|
---
|
|
|
|
I recently watched [a video about separating logic][0] into different categories within your custom code.
|
|
|
|
It wasn't a PHP video, but the concept applies to any programming language or framework.
|
|
|
|
This was the final structure of the directories:
|
|
|
|
```plain
|
|
src/
|
|
Controllers/
|
|
Domain/
|
|
Persistence/
|
|
Properties/
|
|
Services/
|
|
```
|
|
|
|
It was described as using `Controllers` for presentational logic, `Domain` for domain logic, and `Services` for application logic, and reminds me of a domain-driven design (DDD) approach to organising code.
|
|
|
|
I remember watching other older videos showing separating business and presentational logic in React into different components (if I remember correctly).
|
|
|
|
This isn't an approach I see in Drupal code, maybe more-so in other PHP framework-based projects like Symfony or Laravel.
|
|
|
|
It's something I've been thinking of trying, potentially on my website codebase.
|
|
|
|
Do you organise your code in this or a similar way?
|
|
|
|
If so, why?
|
|
|
|
What advantages does it bring?
|
|
|
|
[0]: https://www.youtube.com/watch?v=DuozyaJQQ1U
|