{"id":258187,"date":"2015-05-28T20:11:02","date_gmt":"2015-05-28T16:11:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=258187"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=258187","title":{"rendered":"\u0414\u0432\u043e\u0439\u043d\u0430\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f"},"content":{"rendered":"<p>             \u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043f\u043e \u0441\u043b\u0443\u0436\u0431\u0435 \u0441 \u0432\u0435\u0441\u044c\u043c\u0430 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439. \u041d\u043e \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0434 \u043b\u0443\u043d\u043e\u0439 \u2014 \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u0430\u043c \u0434\u0430\u0432\u043d\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0430: \u0434\u0432\u043e\u0439\u043d\u0430\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 C# \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u043d\u0438\u0436\u0435, \u043d\u043e \u0442\u0435\u043c, \u043a\u0442\u043e \u0438 \u0442\u0430\u043a \u0432\u0441\u0451 \u043f\u043e\u043d\u044f\u043b, \u0441\u043a\u0430\u0436\u0443: \u0434\u0430, \u044f \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u00ab\u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044f\u00bb, \u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u043e.<\/p>\n<p>  \u0415\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0433\u043e\u0432\u043e\u0440\u043e\u043a, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0442\u0440\u043e\u0436\u0435: \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u043e\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u043d\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 dymamic, \u044f\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044f. \u0422\u043e\u043c\u0443 \u0434\u0432\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u044b: 1) \u0446\u0435\u043b\u044c \u2014 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 runtime \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 2) \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044f\u0437\u044b\u043a \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u0435\u043d, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u0440\u0438\u0431\u0435\u0433\u0430\u0442\u044c \u043a \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c \u0438 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0442\u0440\u043e\u0433\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h1>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/h1>\n<p>  \u0418\u043d\u0430\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043d\u0430 \u0440\u0443\u043a\u0430\u0445 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0440\u0430\u0437\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0431\u0449\u0438\u043c \u0438 \u043c\u0430\u043b\u043e\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c. \u0412\u0437\u044f\u0432 \u043b\u044e\u0431\u044b\u0435 \u0434\u0432\u0430 \u0438\u0445 \u043d\u0438\u0445 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0442\u0438\u043f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:   <\/p>\n<ul>\n<li> \u0441\u043a\u0430\u0436\u0435\u043c, \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <b>ICell<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043a\u043b\u0430\u0441\u0441\u044b <b>RedCell<\/b>, <b>BlueCell<\/b>, <b>GreenCell<\/b>.<\/li>\n<li> \u0435\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430: <br \/> \n<ol>\n<li> \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u0434\u0432\u0435 \u043a\u0440\u0430\u0441\u043d\u044b\u0445 \u044f\u0447\u0435\u0439\u043a\u0438, \u043f\u0438\u0448\u0435\u043c \u00ab\u043a\u0440\u0430\u0441\u043d\u043e\u0435 \u043d\u0430 \u043a\u0440\u0430\u0441\u043d\u043e\u043c\u00bb<\/li>\n<li> \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u0437\u0435\u043b\u0451\u043d\u0443\u044e \u0438 \u0441\u0438\u043d\u044e\u044e \u043f\u0438\u0448\u0435\u043c \u00ab\u0431\u0435\u0440\u0435\u0433\u00bb<\/li>\n<li> \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0447\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u2014 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u0446\u0432\u0435\u0442 <\/li>\n<\/ol>\n<p>  <\/li>\n<li> \u043f\u0440\u044f\u043c\u044b\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u044f\u0447\u0435\u0435\u043a \u043d\u0430 \u0441\u0435\u0431\u044f \u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:\n<p>  \u043a\u0440\u0430\u0441\u043d\u043e\u0435 \u043d\u0430 \u043a\u0440\u0430\u0441\u043d\u043e\u043c<br \/>  \u043a\u0440\u0430\u0441\u043d\u044b\u0439 &#8212;&gt; \u0437\u0435\u043b\u0451\u043d\u044b\u0439<br \/>  \u043a\u0440\u0430\u0441\u043d\u044b\u0439 &#8212;&gt; \u0441\u0438\u043d\u0438\u0439<br \/>  \u0437\u0435\u043b\u0451\u043d\u044b\u0439 &#8212;&gt; \u043a\u0440\u0430\u0441\u043d\u044b\u0439<br \/>  \u0437\u0435\u043b\u0451\u043d\u044b\u0439 &#8212;&gt; \u0437\u0435\u043b\u0451\u043d\u044b\u0439<br \/>  \u0431\u0435\u0440\u0435\u0433<br \/>  \u0441\u0438\u043d\u0438\u0439 &#8212;&gt; \u043a\u0440\u0430\u0441\u043d\u044b\u0439<br \/>  \u0441\u0438\u043d\u0438\u0439 &#8212;&gt; \u0437\u0435\u043b\u0451\u043d\u044b\u0439<br \/>  \u0441\u0438\u043d\u0438\u0439 &#8212;&gt; \u0441\u0438\u043d\u0438\u0439  <\/li>\n<\/ul>\n<p>  \u0414\u0443\u043c\u0430\u044e, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u043c \u0445\u0432\u0430\u0442\u0438\u043b\u043e \u0431\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"cs\">internal class Cell     {         public Cell(string color)         {             Color = color;         }          public string Color { get; private set; }     } <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0438\u043a\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043e\u0431\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043d\u043e \u0437\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e \u043d\u0435 \u0441 \u0440\u0443\u043a\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u043c\u0441\u044f: \u0432 \u043e\u0431\u0449\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u043d\u0435\u0442 \u043d\u0438 \u0441\u043b\u043e\u0432\u0430 \u043e \u0446\u0432\u0435\u0442\u0435, \u0430 \u0432\u0441\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0432\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u0430 \u043a\u0440\u0430\u0441\u043d\u0430\u044f \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"cs\">    internal interface ICell     {         \/\/Some code     }      internal class RedCell : ICell     {         public string Color         {             get { return &quot;\u043a\u0440\u0430\u0441\u043d\u044b\u0439&quot;; }         }         \/\/Some code      } <\/code><\/pre>\n<p>  <\/p>\n<h1>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044c<\/h1>\n<p>  \u041a\u043b\u0430\u0441\u0441\u0438\u043a\u043e\u0439 \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u043e\u0434\u043d\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c. \u041e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0451\u043c \u043d\u0435 \u0441\u0442\u0430\u043d\u0443, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/\u041f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044c_(\u0448\u0430\u0431\u043b\u043e\u043d_\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f)\">\u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438<\/a>. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u0431\u044b \u0442\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041f\u0440\u0438 \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 (\u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0437\u0430 [1], \u043d\u0438\u0436\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u044e \u043e \u043d\u0451\u043c):<\/p>\n<pre><code class=\"cs\">    internal interface ICell     {         T AcceptVisitor&lt;T&gt;(ICellVisitor&lt;T&gt; visitor);     }      internal interface ICellVisitor&lt;out T&gt;     {         T Visit(RedCell cell);          T Visit(BlueCell cell);          T Visit(GreenCell cell);     }      internal class RedCell : ICell     {         public string Color         {             get { return &quot;\u043a\u0440\u0430\u0441\u043d\u044b\u0439&quot;; }         }          public T AcceptVisitor&lt;T&gt;(ICellVisitor&lt;T&gt; visitor)         {             return visitor.Visit(this);         }     }      internal class BlueCell : ICell     {         public string Color         {             get { return &quot;\u0441\u0438\u043d\u0438\u0439&quot;; }         }          public T AcceptVisitor&lt;T&gt;(ICellVisitor&lt;T&gt; visitor)         {             return visitor.Visit(this);         }     }      internal class GreenCell : ICell     {         public string Color         {             get { return &quot;\u0437\u0435\u043b\u0451\u043d\u044b\u0439&quot;; }         }          public T AcceptVisitor&lt;T&gt;(ICellVisitor&lt;T&gt; visitor)         {             return visitor.Visit(this);         }     } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044c \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0430\u0448\u0443 \u0437\u0430\u0434\u0430\u0447\u0443:<\/p>\n<pre><code class=\"cs\"> internal class Visitor : ICellVisitor&lt;string&gt;     {         public string Visit(RedCell cell)         {             \/\/ \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u0443\u0436\u0435 \u043d\u0435 \u043a              \/\/ ICell, \u043d\u043e \u043a RedCell \u0438 \u043a \u0435\u0451 \u043d\u0435 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u043d\u043e\u043c\u0443             \/\/ \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 Color             return cell.Color;         }          public string Visit(BlueCell cell)         {             return cell.Color;         }          public string Visit(GreenCell cell)         {             return cell.Color;         }     } <\/code><\/pre>\n<p>  <\/p>\n<h1>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435<\/h1>\n<p>  \u0427\u0442\u043e \u0436, \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043e\u0431\u043e\u0431\u0449\u0438\u0442\u044c \u0438\u043c\u0435\u044e\u0449\u0435\u0435\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0434\u0432\u0443\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u2014 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443 \u0432 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044f: \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u043e\u043d\u0430 \u0438 \u0442\u0430\u043a \u0437\u043d\u0430\u0435\u0442, \u0430, \u043f\u043e\u0441\u0435\u0442\u0438\u0432 \u0441\u0432\u043e\u044e \u0442\u043e\u0432\u0430\u0440\u043a\u0443, \u0443\u0437\u043d\u0430\u0435\u0442 \u0438 \u0435\u0451 \u0442\u0438\u043f, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0440\u0435\u0448\u0438\u0442 \u043d\u0430\u0448\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0447\u0442\u043e (\u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043d\u0430\u043f\u0438\u0448\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043d\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438, \u0430 \u0442\u043e \u043a\u043e\u0434\u0430 \u0438 \u0431\u0435\u0437 \u0442\u043e\u0433\u043e \u043c\u043d\u043e\u0433\u043e): <\/p>\n<pre><code class=\"cs\">internal interface ICell     {         string Color { get; }          T AcceptVisitor&lt;T&gt;(ICellVisitor&lt;T&gt; visitor);     }      internal class RedCell&lt;T&gt; : ICell, ICellVisitor&lt;T&gt;     {         private readonly IProcessor&lt;T&gt; _processor;          public RedCell(IProcessor&lt;T&gt; processor)         {             _processor = processor;         }          public TVisit AcceptVisitor&lt;TVisit&gt;(ICellVisitor&lt;TVisit&gt; visitor)         {             return visitor.Visit(this);         }          public string Color         {             get { return &quot;red&quot;; }         }          public T Visit(RedCell&lt;T&gt; cell)         {             return _processor.Get(this, cell);         }          public T Visit(BlueCell&lt;T&gt; cell)         {             return _processor.Get(this, cell);         }          public T Visit(GreenCell&lt;T&gt; cell)         {             return _processor.Get(this, cell);         }     }      interface IProcessor&lt;T&gt;     {         T Get(RedCell&lt;T&gt; a, RedCell&lt;T&gt; b);         T Get(RedCell&lt;T&gt; a, BlueCell&lt;T&gt; b);         T Get(RedCell&lt;T&gt; a, GreenCell&lt;T&gt; b);     } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u2014 \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440, \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0435\u043d\u0430!<\/p>\n<pre><code class=\"cs\">    internal class Processor : IProcessor&lt;string&gt;     {         public string Get(RedCell&lt;string&gt; a, RedCell&lt;string&gt; b)         {             return &quot;\u043a\u0440\u0430\u0441\u043d\u043e\u0435 \u043d\u0430 \u043a\u0440\u0430\u0441\u043d\u043e\u043c&quot;;         }          public string Get(RedCell&lt;string&gt; a, BlueCell&lt;string&gt; b)         {             return GeneralCase(a, b);         }                  public string Get(RedCell&lt;string&gt; a, GreenCell&lt;string&gt; b)         {             return GeneralCase(a, b);         }          private string GeneralCase(ICell a, ICell b)         {             return a.Color + &quot; --&gt; &quot; + b.Color;         }     } <\/code><\/pre>\n<p>  <\/p>\n<h1>\u041a\u0440\u0438\u0442\u0438\u043a\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h1>\n<p>  \u0427\u0442\u043e \u0436, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e. \u0412\u0430\u043c \u043e\u043d\u043e \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f? \u041c\u043d\u0435 \u2014 \u043d\u0435\u0442. \u041f\u0440\u0438\u0447\u0438\u043d\u044b \u043a\u0430\u043a\u0438\u0435:  <\/p>\n<ul>\n<li>\u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <b>N x N<\/b> \u043c\u0435\u0442\u043e\u0434\u043e\u0432 Visit: \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0435 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e; \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0441 \u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0449\u0451 <b>N+1<\/b> \u043d\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0415\u0441\u043b\u0438 <b>N<\/b> \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0435\u043b\u0438\u043a\u043e (\u0434\u0432\u0430 \u0434\u0435\u0441\u044f\u0442\u043a\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440), \u0442\u043e \u043e\u0431\u044a\u0451\u043c \u043a\u043e\u0434\u0430 \u0438 \u0442\u0440\u0443\u0434\u043e\u0437\u0430\u0442\u0440\u0430\u0442 \u0443\u0441\u0442\u0440\u0430\u0448\u0430\u044e\u0442;<\/li>\n<li>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043b\u044e\u0431\u043e\u0439 \u043d\u043e\u0432\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445. \u0410 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0431\u043e\u0440\u043a\u0430\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440? \u0418, \u0432\u043f\u043e\u043b\u043d\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043e\u0434\u043d\u0443 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0441\u0431\u043e\u0440\u043e\u043a \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u043c\u0435\u043d\u044f\u0442\u044c; <\/li>\n<li>\u0412 \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u0435\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u043c \u043c\u0435\u0442\u043e\u0434\u044b. \u041d\u0443\u0436\u043d\u043e \u043f\u043e\u044f\u0441\u043d\u0438\u0442\u044c \u2014 \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432\u043e\u0432\u0441\u0435 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044f \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e (\u0435\u0441\u043b\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u2014 \u043d\u0435\u043f\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043c\u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435!), \u043d\u043e \u0433\u043e\u0442\u043e\u0432\u044b \u043b\u0438 \u043c\u044b \u0442\u0435\u0440\u043f\u0435\u0442\u044c <b>N+1<\/b> \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 (\u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435!), \u043d\u0435 \u043d\u0435\u0441\u0443\u0449\u0438\u0439 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438? \u0423\u0432\u044b, \u044d\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0443\u0441\u043e\u0440;<\/li>\n<li> \u0412\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u044f\u0447\u0435\u0439\u043a\u0430 \u0441\u0442\u0430\u043b\u0430 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u0439 \u043d\u0430\u0434 T, \u0438\u043c\u0435\u043d\u043d\u043e:\n<pre><code class=\"cs\">class RedCell&lt;T&gt; : ICell, ICellVisitor&lt;T&gt; <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0433\u043e\u0434\u0438\u0442\u0441\u044f! \u042f \u043d\u0435 \u043c\u043e\u0433\u0443 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044f\u0447\u0435\u0439\u043a\u0443, \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432\u0448\u0438\u0441\u044c \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u043a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0432 \u043d\u0435\u0451 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044c! \u041f\u043e\u043b\u043d\u0435\u0439\u0448\u0438\u0439 \u0432\u0437\u0434\u043e\u0440.<\/p>\n<p>  \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f: \u043f\u0443\u0441\u0442\u044c \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442, \u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0451 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442 \u043d\u0430\u0440\u0443\u0436\u0443 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u043e: (1) \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e immutable state \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0441\u043c\u0435\u0449\u0451\u043d\u043d\u043e\u0435 \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 (\u043f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043c\u043d\u0435 \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044e \u2014 \u0434\u0443\u043c\u0430\u044e, \u043e\u043d\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u0430), \u0437\u043d\u0430\u0447\u0438\u0442, \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 (<b>Action<\/b>) \u0438 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (<b>Fun<\/b>), \u0437\u043d\u0430\u0447\u0438\u0442, \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0442\u0438\u043f.  <\/li>\n<\/ul>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u0432\u0430\u0442\u0438\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044c \u043c\u043e\u0451 \u043c\u043d\u0435\u043d\u0438\u0435 \u2014 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0430\u043a \u0441\u0435\u0431\u0435, \u043e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u0432\u0430\u0436\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044f \u0445\u043e\u0447\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. \u0417\u0430\u0434\u0443\u043c\u0430\u0435\u043c\u0441\u044f, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <b>IProcessor<\/b>? <b>N x N<\/b>. \u0422\u043e \u0435\u0441\u0442\u044c, \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e. \u041d\u043e \u0432\u0435\u0434\u044c \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u043b\u044f \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e, \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u043e <b>N<\/b>, \u0447\u0438\u0441\u043b\u0430 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u0418 \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043d\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f (\u0430 \u043c\u044b \u0432\u0435\u0434\u044c \u043f\u0438\u0448\u0435\u043c framework, \u043d\u0435 \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438? \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043e\u0441\u043d\u043e\u0432\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0432\u0441\u0435 \u043f\u043e\u0442\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044f \u043d\u0430\u0448\u0443 \u0441\u0431\u043e\u0440\u043a\u0443 \u043a \u0441\u0432\u043e\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c).<\/p>\n<p>  \u041a\u0430\u043a \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c? \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0448\u0430\u0433: \u043e\u0442\u0434\u0435\u043b\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0442 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044f. \u0414\u0430, \u043f\u0443\u0441\u0442\u044c, \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u043a\u0430\u0436\u0434\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u0443\u043c\u0435\u0435\u0442 <b>AcceptVisitor(&#8230;)<\/b>, \u043d\u043e \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b Visit \u0431\u0443\u0434\u0443\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445. \u041d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f, \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <b>N+1<\/b> \u043a\u043b\u0430\u0441\u0441, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <b>N<\/b> \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <b>Visit<\/b>. \u041d\u0435\u0441\u043b\u0430\u0431\u043e, \u043f\u0440\u0430\u0432\u0434\u0430? \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043b\u044e\u0431\u0430\u044f \u043d\u043e\u0432\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 + \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0443 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445.<\/p>\n<h1>\u041b\u0443\u0447\u0448\u0435\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>  \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u044d\u0442\u0438\u043c\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u0433\u043e\u0432\u043e\u0440\u044e \u0431\u0435\u0437 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0441\u0442\u0438 \u0432\u0440\u043e\u0434\u0435 fluent interface, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u043d\u0435 \u0441\u043c\u043e\u0433 \u0443\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043a \u044d\u0442\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 \u0438\u0445 \u2014 \u0434\u0435\u043b\u043e \u0432\u043a\u0443\u0441\u0430), \u043f\u0440\u0438\u0447\u0451\u043c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043e\u0442 <b>N<\/b> \u0437\u0430\u0432\u0438\u0441\u0438\u0442; \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438 \u043c\u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0435\u0435 \u043e\u0442 <b>N<\/b> \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u044d\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<p>  \u0415\u0441\u043b\u0438 (\u043d\u0443, \u043c\u0430\u043b\u043e \u043b\u0438) \u0432\u044b \u0432\u0441\u0451 \u0435\u0449\u0451 \u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0442\u043e \u0437\u0430\u0434\u0443\u043c\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u0438\u0435, \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0438 \u0432\u044b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0435\u0435 \u044d\u0442\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c?<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043c\u043d\u0435, \u043d\u043e \u043c\u043e\u0451 \u0432\u043e\u0442:<\/p>\n<p>  \u041c\u043e\u0434\u0435\u043b\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0432\u0438\u0434\u0430 [1], \u0430 \u0432\u043e\u0442 \u0442\u0430\u043a (\u0447\u0442\u043e\u0431\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0438\u043d\u0442\u0440\u0438\u0433\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u043e\u0433\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f) \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<pre><code class=\"cs\">internal class ConcreteDispatcherFactory     {         public ICellVisitor&lt;ICellVisitor&lt;string&gt;&gt; CreateDispatcher()         {             return                 new PrototypeDispatcher&lt;string&gt;(Do)                     .TakeRed.WithRed(Do)                     .TakeGreen.WithBlue(Do);         }          private string Do(ICell a, ICell b)         {             return a.Color + &quot;\\t--&gt;\\t&quot; + b.Color;         }          private string Do(GreenCell a, BlueCell b)         {             return &quot;\u043f\u043e\u0431\u0435\u0440\u0435\u0436\u044c\u0435&quot;;         }          private string Do(RedCell a, RedCell b)         {             return &quot;\u043a\u0440\u0430\u0441\u043d\u043e\u0435 \u043d\u0430 \u043a\u0440\u0430\u0441\u043d\u043e\u043c&quot;;         }     } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043c\u044b \u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u0449\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0438 \u0434\u0432\u0430 \u0447\u0430\u0441\u0442\u043d\u044b\u0445, \u0438 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435. <br \/>  \u041f\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u0441\u0447\u0451\u0442\u0443, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044c. \u0412\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u044b\u043c \u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0435\u0433\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438. <\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0435\u0440\u0432\u044b\u0439:<\/p>\n<pre><code class=\"cs\">class PrototypeDispatcher&lt;TResult&gt; : ICellVisitor&lt;ICellVisitor&lt;TResult&gt;&gt;     {         private readonly Builder&lt;TResult, RedCell&gt; _redBuilder;         private readonly Builder&lt;TResult, GreenCell&gt; _greenBuilder;         private readonly Builder&lt;TResult, BlueCell&gt; _blueBuilder;          public PrototypeDispatcher(Func&lt;ICell, ICell, TResult&gt; generalCase)         {             _redBuilder = new Builder&lt;TResult, RedCell&gt;(this, generalCase);             _blueBuilder = new Builder&lt;TResult, BlueCell&gt;(this, generalCase);             _greenBuilder = new Builder&lt;TResult, GreenCell&gt;(this, generalCase);         }          public IBuilder&lt;TResult, RedCell&gt; TakeRed         {             get { return _redBuilder; }         }          public IBuilder&lt;TResult, BlueCell&gt; TakeBlue         {             get { return _blueBuilder; }         }          public IBuilder&lt;TResult, GreenCell&gt; TakeGreen         {             get { return _greenBuilder; }         }          public ICellVisitor&lt;TResult&gt; Visit(RedCell cell)         {             return _redBuilder.Take(cell);         }          public ICellVisitor&lt;TResult&gt; Visit(BlueCell cell)         {             return _blueBuilder.Take(cell);         }          public ICellVisitor&lt;TResult&gt; Visit(GreenCell cell)         {             return _greenBuilder.Take(cell);         }     } <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439:<\/p>\n<pre><code class=\"cs\">    internal class Builder&lt;TResult, TA&gt; : IBuilder&lt;TResult, TA&gt;, ICellVisitor&lt;TResult&gt; where TA : ICell     {         private Func&lt;TA, RedCell, TResult&gt; _takeRed;         private Func&lt;TA, BlueCell, TResult&gt; _takeBlue;         private Func&lt;TA, GreenCell, TResult&gt; _takeGreen;         private readonly Func&lt;ICell, ICell, TResult&gt; _generalCase;          private readonly PrototypeDispatcher&lt;TResult&gt; _dispatcher;         private TA _target;          public Builder(PrototypeDispatcher&lt;TResult&gt; dispatcher, Func&lt;ICell, ICell, TResult&gt; generalCase)         {             _dispatcher = dispatcher;             _generalCase = generalCase;              _takeRed = (a, b) =&gt; _generalCase(a, b);             _takeBlue = (a, b) =&gt; _generalCase(a, b);             _takeGreen = (a, b) =&gt; _generalCase(a, b);         }          public PrototypeDispatcher&lt;TResult&gt; WithRed(Func&lt;TA, RedCell, TResult&gt; toDo)         {             _takeRed = toDo;             return _dispatcher;         }          public PrototypeDispatcher&lt;TResult&gt; WithBlue(Func&lt;TA, BlueCell, TResult&gt; toDo)         {             _takeBlue = toDo;             return _dispatcher;         }          public PrototypeDispatcher&lt;TResult&gt; WithGreen(Func&lt;TA, GreenCell, TResult&gt; toDo)         {             _takeGreen = toDo;             return _dispatcher;         }          public TResult Visit(RedCell cell)         {             return _takeRed(_target, cell);         }          public TResult Visit(BlueCell cell)         {             return _takeBlue(_target, cell);         }          public TResult Visit(GreenCell cell)         {             return _takeGreen(_target, cell);         }          public ICellVisitor&lt;TResult&gt; Take(TA a)         {             _target = a;             return this;         }     } <\/code><\/pre>\n<p>  \u0418 \u0435\u0449\u0451 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044f \u043e\u0442 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044f (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043e\u0431\u043e\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u0441\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u0437\u0430\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439):<\/p>\n<pre><code class=\"cs\">    internal interface IBuilder&lt;TResult, out TA&gt;     {         PrototypeDispatcher&lt;TResult&gt; WithRed(Func&lt;TA, RedCell, TResult&gt; toDo);         PrototypeDispatcher&lt;TResult&gt; WithBlue(Func&lt;TA, BlueCell, TResult&gt; toDo);         PrototypeDispatcher&lt;TResult&gt; WithGreen(Func&lt;TA, GreenCell, TResult&gt; toDo);     } <\/code><\/pre>\n<p>  \u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0445\u043e\u0447\u0443 \u0441\u043e\u0441\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439 <a href=\"http:\/\/ericlippert.com\/2015\/04\/27\/wizards-and-warriors-part-one\/\">\u00ab\u043f\u0440\u043e \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u0438\u043a\u043e\u0432 \u0438 \u0432\u043e\u0438\u043d\u043e\u0432\u00bb<\/a>, \u0433\u0434\u0435 \u0442\u043e\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 C#.             <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/259031\/\"> http:\/\/habrahabr.ru\/post\/259031\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>             \u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043f\u043e \u0441\u043b\u0443\u0436\u0431\u0435 \u0441 \u0432\u0435\u0441\u044c\u043c\u0430 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439. \u041d\u043e \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0434 \u043b\u0443\u043d\u043e\u0439 \u2014 \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u0430\u043c \u0434\u0430\u0432\u043d\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0430: \u0434\u0432\u043e\u0439\u043d\u0430\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 C# \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u043d\u0438\u0436\u0435, \u043d\u043e \u0442\u0435\u043c, \u043a\u0442\u043e \u0438 \u0442\u0430\u043a \u0432\u0441\u0451 \u043f\u043e\u043d\u044f\u043b, \u0441\u043a\u0430\u0436\u0443: \u0434\u0430, \u044f \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u00ab\u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044f\u00bb, \u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u043e.<\/p>\n<p>  \u0415\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0433\u043e\u0432\u043e\u0440\u043e\u043a, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0442\u0440\u043e\u0436\u0435: \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u043e\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u043d\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 dymamic, \u044f\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044f. \u0422\u043e\u043c\u0443 \u0434\u0432\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u044b: 1) \u0446\u0435\u043b\u044c \u2014 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 runtime \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 2) \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044f\u0437\u044b\u043a \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u0435\u043d, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u0440\u0438\u0431\u0435\u0433\u0430\u0442\u044c \u043a \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c \u0438 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0442\u0440\u043e\u0433\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438.  <\/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-258187","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/258187","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=258187"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/258187\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=258187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=258187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=258187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}