FriendsOfTYPO3 / tea

Example extension for unit testing and best practices.
https://typo3.org/community/teams/best-practices
GNU General Public License v2.0
75 stars 23 forks source link

Demonstrate Services and Utility classes #525

Open linawolf opened 2 years ago

linawolf commented 2 years ago

Goal

I as a user want to see some examples of Services and Utility classes.

Acceptance Criteria

Additional Information

Controllers in Extbase should be lean by definition. Business logic should therefore be placed in the namespace VENDOR/Extension/Services if they are stateful and VENDOR/Extension/Utility if they are stateless.

Having business logic beyond control flow in a Controller is a common mistake made by beginners. Business logic in controllers causes problems later on.

So I would love to see an example of Services and Utility classes.

DanielSiepmann commented 1 year ago

@linawolf where did you found the info that "in the namespace VENDOR/Extension/Services if they are stateful"? Services in Domain Driven Design should be stateless. Same is true for Symfony Services.

My opinion: Services are stateless and handle domain logic not placed within a specific model. Utilities don't handle domain logic, but provide language extensions, e.g. ArrayUtility.

I'd prefer to define that before I try to come up with example implementation for EXT:tea.

oliverklee commented 1 year ago

I understand "Utility" as a dumping ground for things we have been unable to put in a more meaningful place. This tends to be like the box "other stuff" in one's home: It's very easy to put things in there, but it's hard to find things there (because when thinking about a thing, you would rather look in its suitable category/folder than in "other stuff" as it's not clear from the thing itself that it's "other stuff").

linawolf commented 1 year ago

I think we had a section explaining the difference between Services and Utility and what is a good Service etc in the docs. Can't find it now. Maybe I dreamed it? Might be a good topic for your team to write about?

DanielSiepmann commented 1 year ago

I've used the search at docs.typo3.org and found the CGL of TYPO3 Core which has definitions for Services and Utilities within TYPO3:

They do not take DDD into account, which is one base concept for Extbase Extensions. I'm therefore not sure whether we should adopt the Core CGL for Extensions.

The docs also reference http://gorodinski.com/blog/2012/04/14/services-in-domain-driven-design-ddd/ which covers Services within DDD.

I'd say we can adopt the Core CGL for /Classes/Services/* and /Classes/Utility/* and need to add something for /Classes/Domain/Service/* in the future with a different issue. What are your opinions @linawolf?

linawolf commented 1 year ago

Sounds like a plan