Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Tech Guidelines: factories vs new keyword #3982

Merged
merged 3 commits into from
Jul 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion guides/v2.2/coding-standards/technical-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ Use [RFC2119] to interpret keywords like:

2.1. Object decomposition MUST follow the [SOLID principles].

2.2. Object MUST be ready for use after instantiation. No additional public initialization methods are allowed.
2.2. Object instantiation

2.2.1. An object MUST be ready for use after instantiation. No additional public initialization methods are allowed.

{% collapsible Examples: %}

Expand Down Expand Up @@ -93,6 +95,11 @@ class Config

---

2.2.2. Factories SHOULD be used for object instantiation instead of `new` keyword. An object SHOULD be replaceable for testing or extensibility purposes.
Exception: [DTOs](https://en.wikipedia.org/wiki/Data_transfer_object). There is no behavior in DTOs, so there is no reason for its replaceability.
Tests can create real DTOs for stubs.
Data interfaces, Exceptions and `Zend_Db_Expr` are examples of DTOs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to add code samples where we can't test or extend some class and how using factories will help to solve this issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe having a blog post would be helpful? I'm afraid adding more explanations here would make the document grow and hard to read.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe having a blog post would be helpful? I'm afraid adding more explanations here would make the document grow and hard to read.

Good idea + add link to that post there


{:start="2.3"}
2.3. Class constructor can have only dependency assignment operations and/or argument validation operations. No other operations are allowed.

Expand Down