{"id":97,"date":"2024-10-07T19:33:43","date_gmt":"2024-10-07T12:33:43","guid":{"rendered":"https:\/\/megadump.ru\/?p=97"},"modified":"2024-12-22T15:42:08","modified_gmt":"2024-12-22T08:42:08","slug":"solid-dip","status":"publish","type":"post","link":"https:\/\/phpha.ru\/?p=97","title":{"rendered":"\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 SOLID (\u0447\u0430\u0441\u0442\u044c 5). \u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0438\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439"},"content":{"rendered":"\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f SOLID:&nbsp;\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0438\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (Dependency inversion principle &#8212; DIP). \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0437\u0432\u0443\u0447\u0438\u0442 \u0442\u0430\u043a &#171;\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043d\u0430 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f\u0445. \u041d\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435&#187;. \u041f\u0440\u0438\u043d\u0446\u0438\u043f, \u043a\u0441\u0442\u0430\u0442\u0438, \u0431\u044b\u043b \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u0432 \u0442\u0440\u0443\u0434\u0430\u0445&nbsp;\u0420\u043e\u0431\u0435\u0440\u0442\u0430 \u041c\u0430\u0440\u0442\u0438\u043d\u0430 (\u0430\u043c\u0435\u0440\u0438\u043a\u0430\u043d\u0441\u043a\u0438\u0439 \u0438\u043d\u0436\u0435\u043d\u0435\u0440, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442). \u0410 \u0442\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430<\/h2>\n\n\n\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430 \u0438 \u0440\u0435\u0448\u0430\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0441 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043e\u043f\u043b\u0430\u0442. \u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0430\u0433\u0430\u0437\u0438\u043d, \u0433\u0434\u0435 \u043e\u043f\u043b\u0430\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u0435. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Cash \u0438 \u043a\u043b\u0430\u0441\u0441 Shop.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\">public class Cash {\n    public void doTransaction(BigDecimal amount){\n        \/\/logic\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\">public class Shop {\n    private Cash cash;\n    public Shop(Cash cash) {\n        this.cash = cash;\n    }\n    public void doPayment(Object order, BigDecimal amount){\n        cash.doTransaction(amount);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u0412\u0440\u043e\u0434\u0435 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u043c\u044b \u0443\u0436\u0435 \u043d\u0430\u0440\u0443\u0448\u0438\u043b\u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0438\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043b\u0438 \u043e\u043f\u043b\u0430\u0442\u0443 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0443. \u0418 \u0435\u0441\u043b\u0438 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u043b\u0430\u0442\u0443 \u0435\u0449\u0435 \u0431\u0430\u043d\u043a\u043e\u0432\u0441\u043a\u043e\u0439 \u043a\u0430\u0440\u0442\u043e\u0439 \u0438 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u043e\u043c (\u0430 \u044d\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c), \u0442\u043e \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041c\u044b \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043b\u0438 \u0441 \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0430 \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0430 \u0443\u0440\u043e\u0432\u043d\u044f \u0437\u0430\u0432\u0438\u0441\u0435\u043b\u0438 \u043e\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438.<\/p>\n\n\n\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Payments.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\">public interface Payments {\n    void doTransaction(BigDecimal amount);\n}<\/code><\/pre>\n\n\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u043e \u043e\u043f\u043b\u0430\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\">public class Cash implements Payments{\n    @Override\n    public void doTransaction(BigDecimal amount) {\n        \/\/logic\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\">public class BankCard implements Payments{\n    @Override\n    public void doTransaction(BigDecimal amount) {\n         \/\/logic\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\">public class PayByPhone implements Payments {\n    @Override\n    public void doTransaction(BigDecimal amount) {\n        \/\/logic \n    }\n}<\/code><\/pre>\n\n\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\">public class Shop {\n    private Payments payments;\n\n    public Shop(Payments payments) {\n        this.payments = payments;\n    }\n\n    public void doPayment(Object order, BigDecimal amount){\n        payments.doTransaction(amount);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0448 \u043c\u0430\u0433\u0430\u0437\u0438\u043d \u0441\u043b\u0430\u0431\u043e \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043e\u043f\u043b\u0430\u0442\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0438 \u0443\u0436\u0435 \u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u043a\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043e\u043f\u043b\u0430\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f (\u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438, \u043a\u0430\u0440\u0442\u043e\u0439 \u0438\u043b\u0438 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u043e\u043c) \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n\n\n\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0432\u0441\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b SOLID. \u0414\u0443\u043c\u0430\u044e, \u0432\u0441\u0435\u043c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u0443\u0437\u043d\u0430\u0442\u044c.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f SOLID:&nbsp;\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0438\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (Dependency inversion principle &#8212; DIP). \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0437\u0432\u0443\u0447\u0438\u0442 \u0442\u0430\u043a &#171;\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043d\u0430 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f\u0445. \u041d\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435&#187;. \u041f\u0440\u0438\u043d\u0446\u0438\u043f, \u043a\u0441\u0442\u0430\u0442\u0438, \u0431\u044b\u043b \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u0432 \u0442\u0440\u0443\u0434\u0430\u0445&nbsp;\u0420\u043e\u0431\u0435\u0440\u0442\u0430 \u041c\u0430\u0440\u0442\u0438\u043d\u0430 (\u0430\u043c\u0435\u0440\u0438\u043a\u0430\u043d\u0441\u043a\u0438\u0439 \u0438\u043d\u0436\u0435\u043d\u0435\u0440, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442). \u0410 \u0442\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e\u0431\u044b &hellip; <a href=\"https:\/\/phpha.ru\/?p=97\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[14,8],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-base","tag-dip","tag-solid"],"_links":{"self":[{"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpha.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=97"}],"version-history":[{"count":6,"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":174,"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions\/174"}],"wp:attachment":[{"href":"https:\/\/phpha.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpha.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpha.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}