{"id":336590,"date":"2022-08-05T03:00:07","date_gmt":"2022-08-05T03:00:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336590"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336590","title":{"rendered":"<span>\u041a\u0430\u043a \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 switch-case \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 switch-case \u0432 \u043a\u043e\u0434\u0435 &#8212; \u0434\u0430\u0432\u043d\u044f\u044f \u0442\u0435\u043c\u0430 \u0445\u043e\u043b\u0438\u0432\u0430\u0440\u043e\u0432 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0430\u0445 \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u043a\u043e\u0434\u0430. \u041b\u0438\u0447\u043d\u043e \u044f \u0441\u043a\u043b\u043e\u043d\u044f\u044e\u0441\u044c \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e: \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e. <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432, \u0433\u0434\u0435 switch-case \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e, <strong><em>\u043a\u0435\u0439\u0441<\/em><\/strong>: \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439.<\/p>\n<p><strong><em>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/em><\/strong>: \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u0437\u043e\u043e\u043f\u0430\u0440\u043a. \u041e\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f <em>Animal<\/em>, \u0438 \u043f\u0430\u0440\u0443 \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <em>ZooWorker<\/em>.<\/p>\n<pre><code class=\"java\">public enum Animal { HIPPO, PENGUIN, MONKEY, OWL; }<\/code><\/pre>\n<pre><code class=\"java\">public interface ZooWorker {     void feed(Animal animal); }<\/code><\/pre>\n<p><strong><em>\u0417\u0430\u0434\u0430\u0447\u0430<\/em><\/strong>: \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432 \u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445 (\u043f\u043e \u0441\u0443\u0442\u0438 &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <em>ZooWorker<\/em>). \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442 &#8212; \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435, \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435 \u043f\u043e\u043a\u043e\u0440\u043c\u043b\u0435\u043d\u043e \u0438 \u0447\u0435\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u043e \u043f\u043e\u043a\u043e\u0440\u043c\u043b\u0435\u043d\u043e.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 java 11. \u041e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u043c \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class Java11Worker implements ZooWorker {      @Override     public void feed(Animal animal) {         String foodName;         switch (animal) {             case OWL:                 foodName = \"Mouse\";                 break;             case HIPPO:                 foodName = \"Grass\";                 break;             case PENGUIN:                 foodName = \"Fish\";                 break;             case MONKEY:                 foodName = \"Banana\";                 break;             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }         System.out.printf(\"%s eat: %s%n\", animal, foodName);     } }<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ol>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0422.\u0435., \u0435\u0441\u043b\u0438 \u0437\u043e\u043e\u043f\u0430\u0440\u043a \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0451\u0442\u0441\u044f \u0434\u043e \u0441\u043e\u0442\u0435\u043d \u0442\u044b\u0441\u044f\u0447 \u0441\u0442\u0440\u043e\u043a, \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0435\u0449\u0435 \u0438 \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435 (\u0438 \u0445\u043e\u0440\u043e\u0448\u043e, \u0435\u0441\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 default, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e).<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445 switch-case \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0451\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443, \u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 switch-case \u0432 java 11 \u2013 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 break, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0442\u044c \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u21164 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class Java11Worker implements ZooWorker {      @Override     public void feed(Animal animal) {         String foodName = getFoodName(animal);         System.out.printf(\"%s eat: %s%n\", animal, foodName);     }      private String getFoodName(Animal animal) {         switch (animal) {             case OWL:                 return  \"Mouse\";             case HIPPO:                 return \"Grass\";             case PENGUIN:                 return \"Fish\";             case MONKEY:                 return \"Banana\";             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }     } }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043b\u0443\u0447\u0448\u0435, \u043e\u0434\u043d\u0430\u043a\u043e, \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 java 14 \u0438 \u0432\u044b\u0448\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 switch-case. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043d\u043e\u0432\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class Java17Worker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         String foodName = switch (animal) {             case OWL -> \"Mouse\";             case HIPPO -> \"Grass\";             case PENGUIN -> \"Fish\";             case MONKEY -> \"Banana\";         };         System.out.printf(\"%s eat: %s%n\", animal, foodName);     } }<\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442 break, \u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u21162: \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435, \u043d\u043e \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 switch-case, \u043a\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0423\u0436\u0435 \u043b\u0443\u0447\u0448\u0435, \u043e\u0434\u043d\u0430\u043a\u043e, \u0442\u0440\u0435\u0442\u044c\u044f \u0438 \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u0441\u0435 \u0435\u0449\u0451 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f. <\/p>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0451\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"java\">public enum Animal {        HIPPO(\"Grass\"),     PENGUIN(\"Fish\"),     MONKEY(\"Banana\"),     OWL(\"Mouse\");      @Getter     private final String foodName;      Animal(String foodName) {         this.foodName = foodName;     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u0430 \u0432\u0441\u0435\u0433\u043e \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<pre><code class=\"java\">public class EasyWorker implements ZooWorker {        @Override     public void feed(Animal animal) {         System.out.printf(\"%s eat: %s%n\", animal, animal.getFoodName());     } }<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438, \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u0433\u0434\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043a\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u043b\u0430\u043f\u0448\u0443 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043d\u0430\u0448 <strong><em>\u043a\u0435\u0439\u0441<\/em><\/strong>: \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u0439, \u043d\u043e \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439.<\/p>\n<p><strong><em>\u0417\u0430\u0434\u0430\u0447\u0430<\/em><\/strong> \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0439 \u0436\u0435 &#8212; \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432 \u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u0440\u043c, \u043d\u043e \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <em>ZooWorker<\/em>:<\/p>\n<pre><code class=\"java\">public interface ZooWorker {     void feed(Animal animal, int animalCount); }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0440\u0430\u0441\u0447\u0451\u0442 \u043a\u043e\u0440\u043c\u0430 \u043d\u0435 \u0432\u0435\u0437\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430:<\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u0431\u0435\u0433\u0435\u043c\u043e\u0442\u043e\u0432: [\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0435\u0433\u0435\u043c\u043e\u0442\u043e\u0432^2]<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0444\u0438\u043b\u0438\u043d\u043e\u0432: [\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0438\u043b\u0438\u043d\u043e\u0432 * 3]<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432: [(\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 ^ 3)\/2]<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043e\u0431\u0435\u0437\u044c\u044f\u043d: [\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0435\u0437\u044c\u044f\u043d * 10]<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c:<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 switch-case \u043d\u0430 java 11<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class Java11Worker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         String foodName;         int foodQuantity;         switch (animal) {             case OWL:                 foodName = \"Mouse\";                 foodQuantity = animalCount * 3;                 break;             case HIPPO:                 foodName = \"Grass\";                 foodQuantity = (int) Math.pow(animalCount, 2);                 break;             case MONKEY:                 foodName = \"Banana\";                 foodQuantity = animalCount * 10;                 break;             case PENGUIN:                 foodName = \"Fish\";                 foodQuantity = (int) (Math.pow(animalCount, 3)\/2);                 break;             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }         System.out.printf(\"%s eat: %d %s\", animal, foodQuantity, foodName);     } }<\/code><\/pre>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class Java11Worker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         String foodName = getFoodName(animal);         int foodQuantity = getfoodQuantity(animal, animalCount);         System.out.printf(\"%s eat: %d %s\", animal, foodQuantity, foodName);     }      private String getFoodName(Animal animal) {         switch (animal) {             case OWL:                 return  \"Mouse\";             case HIPPO:                 return \"Grass\";             case MONKEY:                 return \"Banana\";             case PENGUIN:                 return \"Fish\";             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }     }      private int getfoodQuantity(Animal animal, int animalCount) {         switch (animal) {             case OWL:                 return animalCount * 3;             case HIPPO:                 return (int) Math.pow(animalCount, 2);             case MONKEY:                 return animalCount * 10;             case PENGUIN:                 return (int) (Math.pow(animalCount, 3)\/2);             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }     } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 switch-case \u043d\u0430 java 17<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class Java17Worker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         String foodName = switch (animal) {             case OWL -> \"Mouse\";             case HIPPO -> \"Grass\";             case PENGUIN -> \"Fish\";             case MONKEY -> \"Banana\";         };         int foodQuantity = switch (animal) {             case OWL -> animalCount * 3;             case HIPPO -> (int) Math.pow(animalCount, 2);             case PENGUIN -> (int) (Math.pow(animalCount, 3) \/ 2);             case MONKEY -> animalCount * 10;         };         System.out.printf(\"%s eat: %d %s\", animal, foodQuantity, foodName);     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 enum \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"java\">public enum Animal {      HIPPO(\"Grass\", animalCount -> (int) Math.pow(animalCount, 2)),     PENGUIN(\"Fish\", animalCount -> (int) (Math.pow(animalCount, 3) \/ 2)),     MONKEY(\"Banana\", animalCount -> animalCount * 10),     OWL(\"Mouse\", animalCount -> animalCount * 3);      @Getter     private final String foodName;     @Getter     private final IntFunction&lt;Integer> foodCalculation;      Animal(String foodName, IntFunction&lt;Integer> foodCalculation) {         this.foodName = foodName;         this.foodCalculation = foodCalculation;     } }<\/code><\/pre>\n<p>\u0418, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a:<\/p>\n<pre><code class=\"java\">public class EasyWorker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         System.out.printf(\"%s eat: %d %s\",                            animal,                            animal.getFoodCalculation().apply(animalCount),                            animal.getFoodName()         );     } }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0440\u0430\u0441\u0447\u0451\u0442 \u043a\u043e\u0440\u043c\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043b\u044f\u043c\u0431\u0434\u044b.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0433\u043e.<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class HippoWorker implements ZooWorker {      private final String foodName;      public HippoWorker(String foodName) {         this.foodName = foodName;     }      @Override     public void feed(int animalCount) {         \/\/\u0421\u043b\u043e\u0436\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430         int foodQuantity = (int) Math.pow(animalCount, 2);         System.out.printf(\"Hippo eat: %d %s\", , foodQuantity, foodName);     } }<\/code><\/pre>\n<pre><code class=\"java\">public class MonkeyWorker implements ZooWorker {      private final String foodName;      public MonkeyWorker(String foodName) {         this.foodName = foodName;     }      @Override     public void feed(int animalCount) {         \/\/\u0421\u043b\u043e\u0436\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430         int foodQuantity = animalCount * 10;         System.out.printf(\"Monkey eat: %d %s\", foodQuantity, foodName);     } }<\/code><\/pre>\n<pre><code class=\"java\">public class OwlWorker implements ZooWorker {      private final String foodName;      public OwlWorker(String foodName) {         this.foodName = foodName;     }      @Override     public void feed(int animalCount) {         \/\/\u0421\u043b\u043e\u0436\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430         int foodQuantity = animalCount * 3;         System.out.printf(\"Owl eat: %d %s\", foodQuantity, foodName);     } }<\/code><\/pre>\n<pre><code class=\"java\">public class PenguinWorker implements ZooWorker {      private final String foodName;      public PenguinWorker(String foodName) {         this.foodName = foodName;     }      @Override     public void feed(int animalCount) {         \/\/\u0421\u043b\u043e\u0436\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430         int foodQuantity = (int) (Math.pow(animalCount, 3) \/ 2);         System.out.printf(\"Penguin eat: %d %s\", foodQuantity, foodName);     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u043a\u0430\u043a \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u00ab\u043f\u043e\u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445\u00bb \u00ab\u0432 \u043b\u043e\u0431\u00bb: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a (\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e) \u0432\u0441\u0435\u0445 \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432, \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 feed \u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430. \u0412\u044b\u0448\u043b\u043e \u0431\u044b \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<pre><code class=\"java\">public class Feeder {      private final List&lt;ZooWorker> workerList;      public Feeder(List&lt;ZooWorker> workerList) {         this.workerList = workerList;     }      public void feedAll(int animalCount) {         workerList.forEach(zooWorker -> zooWorker.feed(animalCount));     } }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043e\u0434\u043d\u0430\u043a\u043e, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438  \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0433\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>public void feedHippo(int animalCount)<\/code>, \u0438\u043b\u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 <code>public void feedAnimal(Animal animal, int animalCount)<\/code>? \u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0430\u043f\u044b,\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0432\u0441\u0435\u0445 \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432. \u041d\u043e \u0442\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u043a \u043d\u0435\u0439 (\u0438\u043b\u0438 \u0445\u0430\u0440\u0434\u043a\u043e\u0434\u0438\u0442\u044c). \u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u043e\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0433\u0434\u0435-\u0442\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043c\u0430\u043f\u0443. \u0414\u0440\u0443\u0433\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u0435\u0439, \u043d\u043e \u0438\u0445 [\u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432] \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e, \u0430 <code>feedAnimal <\/code>\u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u044f\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u043c switch-case. \u0418 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c, \u0430 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e \u043a\u043e\u0434\u0443, \u0433\u0434\u0435 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0430 \u043a\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public enum Animal {      HIPPO(new HippoWorker(\"Grass\")),     PENGUIN(new PenguinWorker(\"Fish\")),     MONKEY(new MonkeyWorker(\"Banana\")),     OWL(new OwlWorker(\"Mouse\"));      private final ZooWorker worker;      Animal(ZooWorker worker) {         this.worker = worker;     }      public void feed(int animalCount) {         worker.feed(animalCount);     } } <\/code><\/pre>\n<p>\u0412\u0441\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c:<\/p>\n<pre><code class=\"java\">public class Feeder {          public void feedAll(int animalCount) {         Arrays.stream(Animal.values())                 .forEach(animal -> animal.feed(animalCount));     }      public void feedHippo(int animalCount) {         Animal.HIPPO.feed(animalCount);     }      public void feedAnimal(Animal animal, int animalCount) {         animal.feed(animalCount);     } }<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0432\u0435\u0434\u0435\u043c \u0438\u0442\u043e\u0433\u0438.<\/p>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 3 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0441 \u043d\u0430\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u043e switch-case. \u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043f\u0440\u043e\u0441\u0442\u044b \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u044b \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c &#171;\u0432 \u043b\u043e\u0431&#187; \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c switch-case.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \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\/680940\/\"> https:\/\/habr.com\/ru\/post\/680940\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 switch-case \u0432 \u043a\u043e\u0434\u0435 &#8212; \u0434\u0430\u0432\u043d\u044f\u044f \u0442\u0435\u043c\u0430 \u0445\u043e\u043b\u0438\u0432\u0430\u0440\u043e\u0432 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0430\u0445 \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u043a\u043e\u0434\u0430. \u041b\u0438\u0447\u043d\u043e \u044f \u0441\u043a\u043b\u043e\u043d\u044f\u044e\u0441\u044c \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e: \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e. <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432, \u0433\u0434\u0435 switch-case \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e, <strong><em>\u043a\u0435\u0439\u0441<\/em><\/strong>: \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439.<\/p>\n<p><strong><em>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/em><\/strong>: \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u0437\u043e\u043e\u043f\u0430\u0440\u043a. \u041e\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f <em>Animal<\/em>, \u0438 \u043f\u0430\u0440\u0443 \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <em>ZooWorker<\/em>.<\/p>\n<pre><code class=\"java\">public enum Animal { HIPPO, PENGUIN, MONKEY, OWL; }<\/code><\/pre>\n<pre><code class=\"java\">public interface ZooWorker {     void feed(Animal animal); }<\/code><\/pre>\n<p><strong><em>\u0417\u0430\u0434\u0430\u0447\u0430<\/em><\/strong>: \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432 \u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445 (\u043f\u043e \u0441\u0443\u0442\u0438 &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <em>ZooWorker<\/em>). \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442 &#8212; \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435, \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435 \u043f\u043e\u043a\u043e\u0440\u043c\u043b\u0435\u043d\u043e \u0438 \u0447\u0435\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u043e \u043f\u043e\u043a\u043e\u0440\u043c\u043b\u0435\u043d\u043e.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 java 11. \u041e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u043c \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class Java11Worker implements ZooWorker {      @Override     public void feed(Animal animal) {         String foodName;         switch (animal) {             case OWL:                 foodName = \"Mouse\";                 break;             case HIPPO:                 foodName = \"Grass\";                 break;             case PENGUIN:                 foodName = \"Fish\";                 break;             case MONKEY:                 foodName = \"Banana\";                 break;             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }         System.out.printf(\"%s eat: %s%n\", animal, foodName);     } }<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ol>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0422.\u0435., \u0435\u0441\u043b\u0438 \u0437\u043e\u043e\u043f\u0430\u0440\u043a \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0451\u0442\u0441\u044f \u0434\u043e \u0441\u043e\u0442\u0435\u043d \u0442\u044b\u0441\u044f\u0447 \u0441\u0442\u0440\u043e\u043a, \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0435\u0449\u0435 \u0438 \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435 (\u0438 \u0445\u043e\u0440\u043e\u0448\u043e, \u0435\u0441\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 default, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e).<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445 switch-case \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0451\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443, \u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 switch-case \u0432 java 11 \u2013 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 break, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0442\u044c \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u21164 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class Java11Worker implements ZooWorker {      @Override     public void feed(Animal animal) {         String foodName = getFoodName(animal);         System.out.printf(\"%s eat: %s%n\", animal, foodName);     }      private String getFoodName(Animal animal) {         switch (animal) {             case OWL:                 return  \"Mouse\";             case HIPPO:                 return \"Grass\";             case PENGUIN:                 return \"Fish\";             case MONKEY:                 return \"Banana\";             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }     } }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043b\u0443\u0447\u0448\u0435, \u043e\u0434\u043d\u0430\u043a\u043e, \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 java 14 \u0438 \u0432\u044b\u0448\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 switch-case. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043d\u043e\u0432\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class Java17Worker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         String foodName = switch (animal) {             case OWL -> \"Mouse\";             case HIPPO -> \"Grass\";             case PENGUIN -> \"Fish\";             case MONKEY -> \"Banana\";         };         System.out.printf(\"%s eat: %s%n\", animal, foodName);     } }<\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442 break, \u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u21162: \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435, \u043d\u043e \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 switch-case, \u043a\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0423\u0436\u0435 \u043b\u0443\u0447\u0448\u0435, \u043e\u0434\u043d\u0430\u043a\u043e, \u0442\u0440\u0435\u0442\u044c\u044f \u0438 \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u0441\u0435 \u0435\u0449\u0451 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f. <\/p>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0451\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"java\">public enum Animal {        HIPPO(\"Grass\"),     PENGUIN(\"Fish\"),     MONKEY(\"Banana\"),     OWL(\"Mouse\");      @Getter     private final String foodName;      Animal(String foodName) {         this.foodName = foodName;     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u0430 \u0432\u0441\u0435\u0433\u043e \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<pre><code class=\"java\">public class EasyWorker implements ZooWorker {        @Override     public void feed(Animal animal) {         System.out.printf(\"%s eat: %s%n\", animal, animal.getFoodName());     } }<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438, \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u0433\u0434\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043a\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u043b\u0430\u043f\u0448\u0443 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043d\u0430\u0448 <strong><em>\u043a\u0435\u0439\u0441<\/em><\/strong>: \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u0439, \u043d\u043e \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439.<\/p>\n<p><strong><em>\u0417\u0430\u0434\u0430\u0447\u0430<\/em><\/strong> \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0439 \u0436\u0435 &#8212; \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432 \u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u0440\u043c, \u043d\u043e \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <em>ZooWorker<\/em>:<\/p>\n<pre><code class=\"java\">public interface ZooWorker {     void feed(Animal animal, int animalCount); }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0440\u0430\u0441\u0447\u0451\u0442 \u043a\u043e\u0440\u043c\u0430 \u043d\u0435 \u0432\u0435\u0437\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430:<\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u0431\u0435\u0433\u0435\u043c\u043e\u0442\u043e\u0432: [\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0435\u0433\u0435\u043c\u043e\u0442\u043e\u0432^2]<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0444\u0438\u043b\u0438\u043d\u043e\u0432: [\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0438\u043b\u0438\u043d\u043e\u0432 * 3]<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432: [(\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 ^ 3)\/2]<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043e\u0431\u0435\u0437\u044c\u044f\u043d: [\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0435\u0437\u044c\u044f\u043d * 10]<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c:<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 switch-case \u043d\u0430 java 11<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class Java11Worker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         String foodName;         int foodQuantity;         switch (animal) {             case OWL:                 foodName = \"Mouse\";                 foodQuantity = animalCount * 3;                 break;             case HIPPO:                 foodName = \"Grass\";                 foodQuantity = (int) Math.pow(animalCount, 2);                 break;             case MONKEY:                 foodName = \"Banana\";                 foodQuantity = animalCount * 10;                 break;             case PENGUIN:                 foodName = \"Fish\";                 foodQuantity = (int) (Math.pow(animalCount, 3)\/2);                 break;             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }         System.out.printf(\"%s eat: %d %s\", animal, foodQuantity, foodName);     } }<\/code><\/pre>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class Java11Worker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         String foodName = getFoodName(animal);         int foodQuantity = getfoodQuantity(animal, animalCount);         System.out.printf(\"%s eat: %d %s\", animal, foodQuantity, foodName);     }      private String getFoodName(Animal animal) {         switch (animal) {             case OWL:                 return  \"Mouse\";             case HIPPO:                 return \"Grass\";             case MONKEY:                 return \"Banana\";             case PENGUIN:                 return \"Fish\";             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }     }      private int getfoodQuantity(Animal animal, int animalCount) {         switch (animal) {             case OWL:                 return animalCount * 3;             case HIPPO:                 return (int) Math.pow(animalCount, 2);             case MONKEY:                 return animalCount * 10;             case PENGUIN:                 return (int) (Math.pow(animalCount, 3)\/2);             default:                 throw new IllegalArgumentException(\"Unknown animal!\");         }     } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 switch-case \u043d\u0430 java 17<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class Java17Worker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         String foodName = switch (animal) {             case OWL -> \"Mouse\";             case HIPPO -> \"Grass\";             case PENGUIN -> \"Fish\";             case MONKEY -> \"Banana\";         };         int foodQuantity = switch (animal) {             case OWL -> animalCount * 3;             case HIPPO -> (int) Math.pow(animalCount, 2);             case PENGUIN -> (int) (Math.pow(animalCount, 3) \/ 2);             case MONKEY -> animalCount * 10;         };         System.out.printf(\"%s eat: %d %s\", animal, foodQuantity, foodName);     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 enum \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"java\">public enum Animal {      HIPPO(\"Grass\", animalCount -> (int) Math.pow(animalCount, 2)),     PENGUIN(\"Fish\", animalCount -> (int) (Math.pow(animalCount, 3) \/ 2)),     MONKEY(\"Banana\", animalCount -> animalCount * 10),     OWL(\"Mouse\", animalCount -> animalCount * 3);      @Getter     private final String foodName;     @Getter     private final IntFunction&lt;Integer> foodCalculation;      Animal(String foodName, IntFunction&lt;Integer> foodCalculation) {         this.foodName = foodName;         this.foodCalculation = foodCalculation;     } }<\/code><\/pre>\n<p>\u0418, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a:<\/p>\n<pre><code class=\"java\">public class EasyWorker implements ZooWorker {      @Override     public void feed(Animal animal, int animalCount) {         System.out.printf(\"%s eat: %d %s\",                            animal,                            animal.getFoodCalculation().apply(animalCount),                            animal.getFoodName()         );     } }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0440\u0430\u0441\u0447\u0451\u0442 \u043a\u043e\u0440\u043c\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043b\u044f\u043c\u0431\u0434\u044b.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u043c\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0433\u043e.<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class HippoWorker implements ZooWorker {      private final String foodName;      public HippoWorker(String foodName) {         this.foodName = foodName;     }      @Override     public void<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-336590","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336590","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=336590"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336590\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}