{"id":278019,"date":"2016-04-11T13:15:04","date_gmt":"2016-04-11T09:15:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=278019"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=278019","title":{"rendered":"PHP \u0438 Temporal Coupling"},"content":{"rendered":"<p>       \u041f\u0440\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 PHP \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0435 \u043e\u0434\u0438\u043d \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439, \u043d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0430\u043a\u0446\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 Java \u0438 C#. \u0421\u0443\u0442\u044c \u0435\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0436\u0435\u0441\u0442\u043a\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0435\u0442\u0442\u0435\u0440\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  class Page {     \/**      * @var string      *\/     private $content;      \/**      * @param $content      *\/     public function setContent($content)     {         $this-&gt;content = $content;     } }  class PageBuilder {     \/**      * @var Page      *\/     private $page;      \/**      * @param $page      *\/     public function setPage($page)     {         $this-&gt;page = $page;     }      \/**      * @param $content      * @return $this      *\/     public function setContent($content)     {         $this-&gt;page-&gt;setContent($content);          return $this;     }      \/**      * @return Page      *\/     public function build()     {         return $this-&gt;page;     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<pre><code class=\"php\">$pageBuilder = new PageBuilder(); $pageBuilder-&gt;setPage(new Page()); $pageBuilder-&gt;setContent('Test content'); $pageBuilder-&gt;build(); <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e <b>$pageBuilder-&gt;build()<\/b> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0444\u0430\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0435 \u0435\u0441\u043b\u0438 <b>$pageBuilder-&gt;setPage(new Page())<\/b> \u043d\u0435 \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u043d. \u0414\u0440\u0443\u0433\u0430\u044f \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <b>init()<\/b> \u0438\u043b\u0438 <b>initialization()<\/b>:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">class Page {     \/\/ Class }  class PageBuilder {     \/**      * @var Page      *\/     private $page;      \/**      * Initialization      *\/     public function init()     {         $this-&gt;page = new Page();     }      \/**      * @param $content      * @return $this      *\/     public function setContent($content)     {         $this-&gt;page-&gt;setContent($content);          return $this;     }      \/**      * @return Page      *\/     public function build()     {         return $this-&gt;page;     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<pre><code class=\"php\">$pageBuilder = new PageBuilder(); $pageBuilder-&gt;init(); $pageBuilder-&gt;setContent('Test content'); $pageBuilder-&gt;build(); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <b>init()<\/b>, \u043d\u0430\u0441 \u0442\u0430\u043a\u0436\u0435 \u0436\u0434\u0443\u0442 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043f\u043b\u043e\u0445\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041c\u0435\u0442\u043e\u0434\u044b-\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u043a\u0430\u043a \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e.<\/p>\n<p>  \u0414\u043b\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f Temporal Coupling \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438: <\/p>\n<ul>\n<li>\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0433\u043e\u0442\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f;<\/li>\n<li>\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u0440\u043e\u043c\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043a\u043b\u0430\u0441\u0441\u0430;<\/li>\n<\/ul>\n<p>  <\/p>\n<h2>\u0418\u043d\u044a\u0435\u043a\u0446\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/h2>\n<p>  \u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b Dependency Injection \u0438\u0437 Symfony, Laravel \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u043d\u044a\u0435\u043a\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">class Page {     \/\/ Class }  class PageBuilder {     \/**      * @var Page      *\/     private $page;      \/**      * PageBuilder constructor.      * @param Page $page      *\/     public function __construct(Page $page)     {         $this-&gt;page = $page;     }     \/\/ \u041c\u0435\u0442\u043e\u0434\u044b-\u0441\u0435\u0442\u0442\u0435\u0440\u044b }  $pageBuilder = new PageBuilder(); $pageBuilder-&gt;setContent('Test content'); $pageBuilder-&gt;build(); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h2>\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0430<\/h2>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u0434, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0443\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0443:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">&lt;?php  class Page {     \/\/ Class }  class PageBuilder {     \/**      * @var Page      *\/     private $page;      \/**      * PageBuilder constructor.      * @param Page $page      *\/     public function __construct(Page $page)     {         $this-&gt;page = $page;     }      \/**      * @param $content      * @return $this      *\/     public function setContent($content)     {         $this-&gt;page-&gt;setContent($content);          return $this;     }      \/**      * @return Page      *\/     public function build()     {         return $this-&gt;page;     } }  class PageBuilderFactory implements FactoryInterface {     \/**      * @param Page|null $page      * @return PageBuilder      *\/     public function create(Page $page = null)     {         if (null === $page) {             $page = new Page();         }          return new PageBuilder($page);     } }  $pageBuilderFactory = new PageBuilderFactory(); $pageBuilder = $pageBuilderFactory-&gt;create(); $pageBuilder-&gt;setContent('Test content'); $pageBuilder-&gt;build(); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <b>Page<\/b> \u0441\u043e\u0437\u0434\u0430\u043d \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430\u0448\u0435\u043c\u0443 \u0431\u0438\u043b\u0434\u0435\u0440\u0443.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  Temporal Coupling \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c, \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u043b\u0438\u044f\u043d\u0438\u044f code-review \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u0433\u0438\u043a\u0443, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044f\u043c\u0438. \u0418\u043d\u0430\u0447\u0435 \u0432\u044b \u0440\u0438\u0441\u043a\u0443\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0445\u0443\u0434\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<h2>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/blog.ploeh.dk\/2011\/05\/24\/DesignSmellTemporalCoupling\/\">Design Smell: Temporal Coupling by Mark Seemann<\/a><\/li>\n<li><a href=\"http:\/\/www.yegor256.com\/2015\/12\/08\/temporal-coupling-between-method-calls.html\">Temporal Coupling Between Method Calls<\/a><\/li>\n<li><a href=\"http:\/\/symfony.com\/doc\/current\/components\/dependency_injection\/introduction.html\">Symfony DI<\/a><\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/281330\/\"> https:\/\/habrahabr.ru\/post\/281330\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041f\u0440\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 PHP \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0435 \u043e\u0434\u0438\u043d \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439, \u043d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0430\u043a\u0446\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 Java \u0438 C#. \u0421\u0443\u0442\u044c \u0435\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0436\u0435\u0441\u0442\u043a\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-278019","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/278019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=278019"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/278019\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=278019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=278019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=278019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}