uuid: - value: ed95d76b-0dba-46a3-aa18-2d5f70b07511 langcode: - value: en type: - target_id: daily_email target_type: node_type target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7 revision_timestamp: - value: '2025-05-11T09:00:32+00:00' revision_uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 revision_log: { } status: - value: true uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 title: - value: | Don't inject too many dependencies created: - value: '2023-09-12T00:00:00+00:00' changed: - value: '2025-05-11T09:00:32+00:00' promote: - value: false sticky: - value: false default_langcode: - value: true revision_translation_affected: - value: true path: - alias: /daily/2023/09/12/dont-inject-too-many-dependencies langcode: en body: - value: |
While dependency injection is a good practice - i.e., passing dependencies into a class, usually via a constructor method - you want to be aware of how many dependencies you inject into each class.
There's no hard and fast rule, but I usually notice when I get to three dependencies and rarely inject more than four or five into a class.
Having too many dependencies suggests that the class is doing too much and has too many responsibilities and that another class may be needed.
Having smaller and simpler classes makes them easier to read, maintain and review. Ideally, each class should only have one responsibility, so it adheres to the Single Responsibility Principle (the "S" in SOLID).
Creating classes is cheap, so why not split one large and difficult-to-maintain class with many dependencies into multiple smaller and easier-to-work-with ones?
format: full_html processed: |While dependency injection is a good practice - i.e., passing dependencies into a class, usually via a constructor method - you want to be aware of how many dependencies you inject into each class.
There's no hard and fast rule, but I usually notice when I get to three dependencies and rarely inject more than four or five into a class.
Having too many dependencies suggests that the class is doing too much and has too many responsibilities and that another class may be needed.
Having smaller and simpler classes makes them easier to read, maintain and review. Ideally, each class should only have one responsibility, so it adheres to the Single Responsibility Principle (the "S" in SOLID).
Creating classes is cheap, so why not split one large and difficult-to-maintain class with many dependencies into multiple smaller and easier-to-work-with ones?
summary: null field_daily_email_cta: { }