From 140d8b3dd0cd8791a4c1c3cbffcc3d0f37a03f01 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Wed, 20 Mar 2019 17:55:38 -0500 Subject: [PATCH 1/2] tech Guidelines: factories vs `new` keyword --- guides/v2.2/coding-standards/technical-guidelines.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/guides/v2.2/coding-standards/technical-guidelines.md b/guides/v2.2/coding-standards/technical-guidelines.md index 869da15a93b..f7e65003249 100644 --- a/guides/v2.2/coding-standards/technical-guidelines.md +++ b/guides/v2.2/coding-standards/technical-guidelines.md @@ -49,7 +49,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: %} @@ -98,6 +100,11 @@ class Config {% endcollapsible %} --- +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. 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. + {:start="2.3"} 2.3. Class constructor can have only dependency assignment operations and/or argument validation operations. No other operations are allowed. From 238c64b910d825f40343be9587ac0b71d37b2fb5 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 21 Mar 2019 15:51:26 -0500 Subject: [PATCH 2/2] Tech Guidelines: factories vs `new` keyword - added reference to DTO definition --- guides/v2.2/coding-standards/technical-guidelines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/v2.2/coding-standards/technical-guidelines.md b/guides/v2.2/coding-standards/technical-guidelines.md index f7e65003249..dfb77da3787 100644 --- a/guides/v2.2/coding-standards/technical-guidelines.md +++ b/guides/v2.2/coding-standards/technical-guidelines.md @@ -101,7 +101,7 @@ 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. There is no behavior in DTOs, so there is no reason for its replaceability. +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.