{"id":304853,"date":"2020-06-04T21:00:32","date_gmt":"2020-06-04T21:00:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=304853"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=304853","title":{"rendered":"\u041a\u0430\u043a \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438?"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/505400\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ir\/fv\/ky\/irfvkyn9faieranihlz8fcvxxcu.jpeg\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0432\u0441\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u0447\u0442\u043e \u043f\u0440\u043e \u043c\u043e\u0434\u0435\u043b\u0438, MVC, AR \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 <strong>\u0441\u043b\u043e\u0432\u0430<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u0432\u0441\u0435 \u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442, \u0447\u0442\u043e \u044d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442?<br \/>  \u0412\u0441\u0435 \u043b\u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043a\u0430\u043a \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0435\u043c (\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e) \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"patterny\">\u041f\u0430\u0442\u0442\u0435\u0440\u043d\u044b<\/h2>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c \u0438 \u0438\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c \u043c\u043e\u0434\u0435\u043b\u0438 (\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a <a href=\"http:\/\/design-pattern.ru\" rel=\"nofollow\">design-pattern.ru<\/a>):<\/p>\n<p>  <\/p>\n<ul>\n<li><strong>MVC (Model View Controller) \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>. \u041a\u0440\u0430\u0442\u0435\u043d\u044c\u043a\u043e \u0438 \u043e\u0447\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e;<\/li>\n<li><strong>AR (Active Record) \u2014 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c<\/strong>. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043c\u043d\u043e\u0433\u043e \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u043d\u0430 \u0440\u043e\u0432\u043d\u043e \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043d\u0430\u0441\u044b\u0449\u0435\u043d\u043d\u043e\u0439, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0438\u0434\u0435\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0432 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u0435 \u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0443\u0436 \u0440\u0430\u0431\u043e\u0447\u0435\u0439;<\/li>\n<li><strong>DM (Domain Model) \u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u043d\u0430\u0447\u0430\u0449\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c<\/strong>. \u0412\u043e\u0442 \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438. \u041c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435!<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0440\u0435\u0448\u0438\u043b\u0438 \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430, \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043f\u0440\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"kazhdoy-modeli-svoy-repozitoriy\">\u041a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0432\u043e\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h2>\n<p>  <\/p>\n<p>\u0422.\u043a. \u043c\u043e\u0434\u0435\u043b\u044c \u044d\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430, \u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u0411\u0414 \u043d\u0430\u0448\u0438 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0415\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439: <\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u0447\u0430\u0435\u0442 \u043c\u0435\u0436\u0434\u0443 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (domain and data mapping layers), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0441\u0445\u043e\u0436\u0438\u0439 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 1 \u043c\u043e\u0434\u0435\u043b\u044c\u044e.<\/p>\n<p>  <\/p>\n<p><strong>\u041d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c<\/strong> \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u0442\u0438\u043f\u0430 <code>BlogRepository<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0431\u043b\u043e\u0433\u0430, \u0438\u043b\u0438 <code>PostRepository<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0449\u0435 \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438.<br \/>  \u0413\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ot\/0e\/ab\/ot0eabcy7dhwippbsxrinxuddty.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e \u0432 \u0441\u043b\u043e\u0435 \u0434\u043e\u043c\u0435\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u0431\u0435\u0437 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438 \u0434\u043e\u043c\u0435\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 \u0438 \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0434\u043e\u043c\u0435\u043d\u0430 \u0438 \u043e\u043a).<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445, \u0443 \u043d\u0430\u0441 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0431\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0434\u043e\u043c\u0435\u043d\u0430, \u0430 \u0441\u0440\u0430\u0437\u0443 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u043c \u0441\u043b\u043e\u0435.<\/p>\n<p>  <\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043d\u0435 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u043a\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"modeli---eto-suschnosti-a-ne-tablicy\">\u041c\u043e\u0434\u0435\u043b\u0438 \u2014 \u044d\u0442\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0430 \u043d\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/h2>\n<p>  <\/p>\n<p>\u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0411\u0414).<br \/>  \u0418 \u0434\u0430\u043b\u044c\u0448\u0435 \u0443\u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0438\u0445 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f, \u0442.\u0435. \u043e\u0442 \u0442\u0430\u0431\u043b\u0438\u0446.<br \/>  \u041d\u043e \u044d\u0442\u043e <strong>\u0432 \u043a\u043e\u0440\u043d\u0435<\/strong> \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u043b\u043e\u0433\u0430.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u0438\u043c\u0435\u0435\u043c:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041f\u043e\u0441\u0442<\/li>\n<li>\u0410\u0432\u0442\u043e\u0440<\/li>\n<li>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/li>\n<li>\u0422\u044d\u0433\u0438<\/li>\n<li>\u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u0430 \u0438 \u043d\u0430\u0440\u0430\u0449\u0438\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u043e\u0441\u0442\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">interface PostRepository {     public function save(Post $model); }  class Post {     protected $id;     protected $title;     protected $content;      public function setId(int $id)     {         $this-&gt;id = $id;     }      public function getId(): ?int     {         return $this-&gt;id;     }      public function setTitle(string $title)     {         $this-&gt;title = $title;     }      public function getTitle(): string     {         return $this-&gt;title ?: '';     }      public function setContent(string $content)     {         $this-&gt;content = $content;     }      public function getContent(): string     {         return $this-&gt;content ?: '';     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0442\u0430\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0438 \u0440\u0435\u043f\u043e\u0439, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$post = new Post(); $post-&gt;setTitle('Title'); $post-&gt;setContent('...'); $repo-&gt;save($post);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043d\u0435\u0434\u0440\u0438\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <code>\u0410\u0432\u0442\u043e\u0440<\/code>, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class Post {     \/\/ ...      protected $author;      public function setAuthor(Author $author)     {         $this-&gt;author = $author;     }      public function getAuthor(): Author     {         return $this-&gt;author;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$author = $authorRepo-&gt;getById(1); $post-&gt;setAuthor($author); $repo-&gt;save($post);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043d\u0435\u0434\u0440\u0438\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <code>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/code>, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0442\u043e\u0436\u0435 \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0442\u0442\u0435\u0440 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043f\u043e\u043b\u0435, \u043d\u043e \u0435\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u043c\u044b\u0441\u043b\u044b, \u0442\u043e \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u043a\u0430\u043a &quot;\u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438&quot;, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u043a\u0430\u043a &quot;\u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439&quot; \u0438 &quot;\u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439&quot;.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0448\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class Post {     \/\/ another code      protected $comments;     protected $addComments = [];     protected $removeComments = [];      public function getComments()     {         return $this-&gt;comments;     }      public function addComment(Comment $comment)     {         $this-&gt;addComments[] = $comment;     }      public function getAddComments()     {         return $this-&gt;addComments;     }      public function removeComment(Comment $comment)     {         $this-&gt;removeComments[] = $comment;     }      public function getRemoveComments()     {         return $this-&gt;removeComments;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$newComment = new Comment(); $newComment-&gt;setContent(&quot;...&quot;);  $removeComment = $commentRepo-&gt;getById(1);  $post-&gt;addComment($newComment); $post-&gt;removeComment($removeComment); $repo-&gt;save($post);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430, \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u0441\u0430\u043c <code>PostRepository<\/code> \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043d\u0430 <code>CommentRepository<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043f\u043e\u0441\u0442\u043e\u0432, \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class ConcretePostRepository implements PostRepository {     protected $commentRepository;      public function setCommentRepository(CommentRepository $commentRepository)     {         $this-&gt;commentRepository = $commentRepository;     }      public function save(Post $post)     {         if ($post-&gt;getId()) {             $this-&gt;update($post);         }         else {             $this-&gt;insert($post);         }          foreach ($post-&gt;getAddComments() as $comment) {             $this-&gt;commentRepository-&gt;save($comment);             $this-&gt;linkCommentToPost($post, $comment);         }         foreach ($post-&gt;getRemoveComments() as $comment) {             $this-&gt;unlinkCommentToPost($post, $comment);             $this-&gt;commentRepository-&gt;remove($comment);         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0430\u0436\u043d\u043e \u0443\u0447\u0435\u0441\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u0432\u044f\u0437\u044c &quot;\u043f\u043e\u0441\u0442 \u2014 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439&quot; \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u0442\u043e \u0443 \u043d\u0430\u0441 <strong>\u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c<\/strong> \u043c\u0435\u0442\u043e\u0434\u0430 <code>setPost<\/code>, \u0442.\u043a. \u043e\u043d \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u0441\u0432\u044f\u0437\u044c &quot;\u0446\u0435\u043b\u043e\u0435 \u2014 \u0447\u0430\u0441\u0442\u044c&quot;.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0447\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>getPost<\/code> \u044d\u0442\u0443 \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435, \u043c\u044b \u043c\u0435\u043d\u044f\u0435\u043c &quot;\u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430&quot; \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0435: \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0441\u0442, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439.<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$post = $repo-&gt;getById(1);  $comment = new Comment(); $comment-&gt;setContent('...'); $comment-&gt;setPost($post); \/\/ \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u044b\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e! $commentRepo-&gt;save($comment);  $post = $comment-&gt;getPost(); \/\/ \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0435\u043d<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>\u0422\u044d\u0433\u0438<\/code>, \u0435\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u043c\u044b\u0441\u043b, \u0442\u043e \u0437\u0434\u0435\u0441\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 &quot;\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0442\u044d\u0433\u0438&quot;.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u0435\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043c\u0435\u0442\u043e\u0434\u044b <code>addTag<\/code> \u0438 <code>removeTag<\/code> \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class Post {     \/\/ another code      protected $tags;      public function setTags(TagCollection $tags)     {         $this-&gt;tags = $tags;     }      public function addTag(Tag $tag)     {         if (!$this-&gt;tags) {             $this-&gt;tags = new TagCollection;         }         $this-&gt;tags-&gt;add($tag);     }      public function removeTag(Tag $tag)     {         if ($this-&gt;tags instanceof TagCollection) {             $this-&gt;tags-&gt;remove($tag);         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0442\u0435\u0433\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$tag1 = $tagRepo-&gt;getById(1); $tag2 = new Tag(); $tag2-&gt;setValue('...'); $tag3 = $tagRepo-&gt;getById(3);  $post-&gt;setTags(new TagCollection($tag1, $tag2)); \/\/ \u0438\u043b\u0438 $post-&gt;addTag($tag1); $post-&gt;addTag($tag2); $post-&gt;removeTag($tag3); $repo-&gt;save($post);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0432\u044f\u0437\u044c &quot;\u043f\u043e\u0441\u0442 \u2014 \u0442\u044d\u0433\u0438&quot; \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>\u0422\u044d\u0433\u0438<\/code>, \u0442\u043e \u043c\u044b \u043e\u043f\u044f\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>setPosts<\/code> \u0442.\u043a. \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u043c \u0441\u0432\u044f\u0437\u044c &quot;\u0446\u0435\u043b\u043e\u0435 \u2014 \u0447\u0430\u0441\u0442\u044c&quot; (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>post has tag<\/code>, \u0430 \u043d\u0435 <code>tag has post<\/code>).<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438 \u043c\u0435\u0442\u043e\u0434 <code>getPosts<\/code> \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u0441\u0432\u044f\u0437\u044c &quot;\u0446\u0435\u043b\u043e\u0435 \u2014 \u0447\u0430\u0441\u0442\u044c&quot;.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0441\u0442\u043e\u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0435\u0433\u0430 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">interface PostRepository {     public function getListByTag(Tag $tag); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>\u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0442\u0443\u0442 \u0432\u0441\u0435 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0442\u043e \u0438 \u0443 \u0442\u044d\u0433\u043e\u0432, \u043d\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442: \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u043e\u0441\u0442\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439, \u0442.\u0435. \u043f\u043e\u0441\u0442\u044b &quot;\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f&quot; \u0432 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043a\u0430\u043a \u0432 \u043f\u0430\u043f\u043a\u0438, \u0430 \u043d\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a \u043f\u043e\u0441\u0442\u0430\u043c, \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0442\u044d\u0433\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u0430 \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043b\u0438\u0448\u044c \u0433\u0435\u0442\u0442\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class Post {     \/\/ another code      protected $categories;      public function getCategories()     {         return $this-&gt;categories;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$post = $postRepo-&gt;getById(1);  $cat1 = $categoryRepo-&gt;getById(1); $cat1-&gt;addPost($post); $categoryRepo-&gt;save($cat1); \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0443 \u043a \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438  $cat2 = $categoryRepo-&gt;getById(2); $cat2-&gt;addPost($post); $categoryRepo-&gt;save($cat2); \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0443 \u043a \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438  $cat3 = $categoryRepo-&gt;getById(3); $cat3-&gt;removePost($post); $categoryRepo-&gt;save($cat3); \/\/ \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0443 \u043a \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438  [$cat1, $cat2] = $post-&gt;getCategories();<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"biznes-deystviya\">\u0411\u0438\u0437\u043d\u0435\u0441-\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 <code>Post<\/code>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u0439.<\/p>\n<p>  <\/p>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0435\u0449\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0430 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u0440\u0430\u043d\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">Post.php<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">class Post {     protected $id;     protected $title;     protected $content;     protected $author;     protected $tags;     protected $comments;     protected $addComments = [];     protected $removeComments = [];      public function setId(int $id)     {         $this-&gt;id = $id;     }      public function getId(): ?int     {         return $this-&gt;id;     }      public function setTitle(string $title)     {         $this-&gt;title = $title;     }      public function getTitle(): string     {         return $this-&gt;title ?: '';     }      public function setContent(string $content)     {         $this-&gt;content = $content;     }      public function getContent(): string     {         return $this-&gt;content ?: '';     }      public function setAuthor(Author $author)     {         $this-&gt;author = $author;     }      public function getAuthor(): Author     {         return $this-&gt;author;     }      public function getComments()     {         return $this-&gt;comments;     }      public function addComment(Comment $comment)     {         $this-&gt;addComments[] = $comment;     }      public function getAddComments()     {         return $this-&gt;addComments;     }      public function removeComment(Comment $comment)     {         $this-&gt;removeComments[] = $comment;     }      public function getRemoveComments()     {         return $this-&gt;removeComments;     }      public function setTags(TagCollection $tags)     {         $this-&gt;tags = $tags;     }      public function addTag(Tag $tag)     {         if (!$this-&gt;tags) {             $this-&gt;tags = new TagCollection;         }         $this-&gt;tags-&gt;add($tag);     }      public function removeTag(Tag $tag)     {         if ($this-&gt;tags instanceof TagCollection) {             $this-&gt;tags-&gt;remove($tag);         }     } }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u043a \u043f\u043e\u0441\u0442\u0443, \u0443 \u043d\u0430\u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0447\u0435\u043c \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f.<br \/>  \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u0438 \u0442\u0443 \u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u043c\u043e\u0436\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 &quot;\u0431\u0438\u0437\u043d\u0435\u0441-\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f&quot;, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043e\u0434\u043d\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435.<br \/>  \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">abstract class BusinessOperation {     abstract public function run();      public static function createInstance(): self     {         \/\/ DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440         return Container::getInstance()-&gt;make(get_called_class());     } }  abstract class Model {     private $operations = [];      protected function addOperation(BusinessOperation $item)     {         $this-&gt;operations[] = $item;     }      public function getOperations(): array     {         return $this-&gt;operations;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f &quot;\u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0430 \u043f\u043e\u0441\u0442\u0430&quot; \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class NotifyAuthorAboutComment extends BusinessOperation {     protected $service;     protected $post;      public function __construct(NotifyService $service)     {         $this-&gt;service = $service;     }      public function setPost(Post $post)     {         $this-&gt;post = $post;     }      public function run()     {         $author = $this-&gt;post-&gt;getAuthor();         $notify = new Nofity();         $notify-&gt;setOwner($author);         $notify-&gt;setContent(&quot;\u041d\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043a \u0437\u0430\u043f\u0438\u0441\u0438 '{$this-&gt;post-&gt;title}'&quot;);          $this-&gt;service-&gt;send($notify);     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0443 \u043d\u0430\u0441 \u0442\u043e\u0436\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c \u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">abstract class ModelRepository {     protected function saveInternal(Model $model)     {         try {             $this-&gt;startTransaction();             if ($model-&gt;isNewRecord()) {                 $this-&gt;insert($model);             }             else {                 $this-&gt;update($model);             }             foreach ($model-&gt;getOperations() as $operation) {                 $operation-&gt;run();             }             $this-&gt;commitTransaction();         }         catch (Throwable $e) {             $this-&gt;rollbackTransaction();             throw $e;         }     } }  class ConcretePostRepository extends ModelRepository implements PostRepository {     public function save(Post $post)     {         $this-&gt;saveInternal($post);     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0430\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0430\u0442\u043a\u043e\u0439, \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u043a \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044e:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">Post.php<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">class Post extends Model {     protected $id;     protected $title;     protected $content;     protected $author;     protected $tags;     protected $comments;      public function setId(int $id)     {         $this-&gt;id = $id;     }      public function getId(): ?int     {         return $this-&gt;id;     }      public function setTitle(string $title)     {         $this-&gt;title = $title;     }      public function getTitle(): string     {         return $this-&gt;title ?: '';     }      public function setContent(string $content)     {         $this-&gt;content = $content;     }      public function getContent(): string     {         return $this-&gt;content ?: '';     }      public function setAuthor(Author $author)     {         $this-&gt;author = $author;     }      public function getAuthor(): Author     {         return $this-&gt;author;     }      public function getComments()     {         return $this-&gt;comments;     }      public function addComment(Comment $comment)     {         $action = new AddComment();         $action-&gt;setPost($this);         $action-&gt;setComment($value);         $this-&gt;addOperation($action);          $action = new NotifyAuthorAboutChange();         $action-&gt;setPost($this);         $this-&gt;addOperation($action);     }      public function removeComment(Comment $comment)     {         $action = new RemoveComment();         $action-&gt;setPost($this);         $action-&gt;setComment($value);         $this-&gt;addOperation($action);     }      public function setTags(TagCollection $tags)     {         $this-&gt;tags = $tags;     }      public function addTag(Tag $tag)     {         if (!$this-&gt;tags) {             $this-&gt;tags = new TagCollection;         }         $this-&gt;tags-&gt;add($tag);     }      public function removeTag(Tag $tag)     {         if ($this-&gt;tags instanceof TagCollection) {             $this-&gt;tags-&gt;remove($tag);         }     } }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h2 id=\"pochemu-ploho-narushat-svyaz-celoe---chast\">\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u043b\u043e\u0445\u043e \u043d\u0430\u0440\u0443\u0448\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u044c &quot;\u0446\u0435\u043b\u043e\u0435 \u2014 \u0447\u0430\u0441\u0442\u044c&quot;<\/h2>\n<p>  <\/p>\n<p>\u0420\u0430\u043d\u0435\u0435 \u043d\u0435\u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438\u0437-\u0437\u0430 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u0441\u0432\u044f\u0437\u0438 &quot;\u0446\u0435\u043b\u043e\u0435 \u2014 \u0447\u0430\u0441\u0442\u044c&quot;.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u0430\u0437\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438.<\/p>\n<p>  <\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: \u0437\u0430\u043a\u0430\u0437 \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u0432\u0430\u0440\u044b, \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u043e\u043f\u043b\u0430\u0442\u0435 \u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0435, \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043e\u043f\u043b\u0430\u0442\u044b \u0443 \u043d\u0430\u0441 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430, \u0441\u0442\u0430\u0442\u0443\u0441 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 (\u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0430) \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430\u043c \u0438 \u0441\u0430\u043c\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043e\u043f\u043b\u0430\u0442\u0443 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0435 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/ \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u043f\u043b\u0430\u0442\u044b, \u0432\u0430\u0436\u043d\u043e \u0442\u043e \u043a\u0430\u043a \u043c\u044b \u0435\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 $payment = $repo-&gt;getById(1); $payment = $order-&gt;getPayment();  $payment-&gt;setPaidAmount(100); if ($payment-&gt;isPaid()) {     $payment-&gt;setStatus(IS_PAID); } $repo-&gt;save($payment);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442?<\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0441\u0443\u043c\u043c\u0443 \u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u043e\u043f\u043b\u0430\u0442\u044b, \u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439.<br \/>  \u041d\u043e \u0435\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043e\u043f\u043b\u0430\u0442\u044b \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$order = $repo-&gt;getById(1); $order-&gt;setPaidAmount(100); $repo-&gt;save($order);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043a\u0430\u0437\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  <\/p>\n<p>\u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u044c &quot;\u0446\u0435\u043b\u043e\u0435 \u2014 \u0447\u0430\u0441\u0442\u044c&quot;, \u0447\u0442\u043e\u0431\u044b \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0430 \u043a\u0430\u043a \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0435 \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043e\u043a: \u0432\u043c\u0435\u0441\u0442\u043e &quot;\u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u043f\u043b\u0430\u0442\u0443&quot;, \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0443 &quot;\u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u043f\u043b\u0430\u0442\u0443 \u043f\u043e \u0437\u0430\u043a\u0430\u0437\u0443&quot;, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 \u044f\u0441\u043d\u043e \u0433\u0434\u0435 \u0446\u0435\u043b\u043e\u0435 \u0438 \u043a\u0430\u043a \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"para-slov-pro-repozitorii\">\u041f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043f\u0440\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u0427\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u0445\/\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">interface BaseRepository {     \/**      * @param Condition $condition \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438      *\/     public function getList(Condition $condition); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0432\u0441\u0442\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043f\u0430\u0440\u043e\u0447\u043a\u0430 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432:<\/p>\n<p>  <\/p>\n<ol>\n<li><strong>\u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0435: \u043f\u043e\u043b\u044f \u0434\u043e\u043c\u0435\u043d\u0430 \u0438\u043b\u0438 \u043f\u043e\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b?<\/strong> \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043e\u043c\u0435\u043d\u0430 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0411\u0414. \u041f\u0440\u0438 \u0432\u0442\u043e\u0440\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0432\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0435\u0441\u044c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 (\u0441\u043c. \u043f\u0443\u043d\u043a\u0442 2);<\/li>\n<li><strong>\u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0431\u043e\u043b\u0438?<\/strong> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445: \u0440\u0430\u043d\u0435\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0430 \u0441\u0432\u044f\u0437\u044c 1:M, \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0442\u0430\u043b\u0430 N:M. \u0422.\u0435. \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u044b \u0443\u0431\u0440\u0430\u043b\u0438 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0438 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432 Condition, \u0438 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432\u044b \u0441\u0432\u044f\u0437\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (\u0430 \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435, \u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0443\u0434\u0435\u0442).<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c?<\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442 \u2014 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u0430 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u0432\u0441\u0435 \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">interface CommentRepository {     public function getListByPost(Post $post);      public function getLastByPost(Post $post);      public function getListPopular();      public function getById(int $id); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0442.\u043a. \u043c\u044b \u0437\u0430\u0432\u0438\u0441\u0438\u043c <strong>\u0442\u043e\u043b\u044c\u043a\u043e<\/strong> \u043e\u0442 \u0434\u043e\u043c\u0435\u043d\u0430. \u0418 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u0438 \u2014 \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0432\u0435\u0449\u044c, \u043d\u043e \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0447\u0442\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u044d\u0442\u0438\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043c.<br \/>  \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439, \u0431\u0435\u0437 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0434\u043e\u043c\u0435\u043d\u0430, \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0434\u0430\u0435\u0442 \u0440\u044f\u0434 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0439 \u0434\u043e\u043c\u0435\u043d\u0430 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u044d\u0442\u043e \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438;<\/li>\n<li>\u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0430\u043c\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0442.\u043a. \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0431\u0443\u0434\u0443\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f, \u0430 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u043e\u043c \u043a\u0430\u043a \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c;<\/li>\n<li>\u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u0437\u0430 \u0441\u0447\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0443 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0438 \u0433\u0438\u0431\u043a\u0438\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439;<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435.<\/p>\n<\/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:\/\/habr.com\/ru\/post\/505400\/\"> https:\/\/habr.com\/ru\/post\/505400\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/505400\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ir\/fv\/ky\/irfvkyn9faieranihlz8fcvxxcu.jpeg\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0432\u0441\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u0447\u0442\u043e \u043f\u0440\u043e \u043c\u043e\u0434\u0435\u043b\u0438, MVC, AR \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 <strong>\u0441\u043b\u043e\u0432\u0430<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u0432\u0441\u0435 \u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442, \u0447\u0442\u043e \u044d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442?<br \/>  \u0412\u0441\u0435 \u043b\u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043a\u0430\u043a \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0435\u043c (\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e) \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443.<\/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-304853","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304853","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=304853"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304853\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}