{"id":468255,"date":"2025-07-22T21:00:13","date_gmt":"2025-07-22T21:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=468255"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=468255","title":{"rendered":"<span>\u0424\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 Python<\/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<h2>\u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c (observer)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 &#171;\u043e\u0434\u0438\u043d \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c&#187; \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c. \u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0438 &#8212; \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0430\u0446\u0438\u0435\u043d\u0442 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 \u0438 \u043f\u0443\u043b\u044c\u0441 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0430\u0446\u0438\u0435\u043d\u0442 &#8212; \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b (\u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0438 \u043f\u0443\u043b\u044c\u0441). \u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0438 &#8212; \u0431\u043b\u043e\u043a\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044f\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0442\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<pre><code class=\"python\">class AbstractClass:     \"\"\"         \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:         add_obs - \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f         remove_obs - \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f         notify_observer - \u0440\u0430\u0437\u043e\u0441\u043b\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f\u043c     \"\"\"      def __init__(self):         self.__observers = []      def add_obs(self, observer):         self.__observers.append(observer)      def remove_obs(self, observer):         self.__observers.remove(observer)      def notify_observer(self, *arg):         for i in self.__observers:             i.update(self, *arg)<\/code><\/pre>\n<pre><code class=\"python\">class AbstractObserver:     \"\"\"         \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c         \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f\u043c \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434 update, \u043a\u043e\u0442\u043e\u0440\u044b\u0439      \"\"\"      def __init__(self):         pass      def update(self):         pass<\/code><\/pre>\n<pre><code class=\"python\">class Patient(AbstractClass):     \"\"\"         \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u0430\u0446\u0438\u0435\u043d\u0442 - \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442         \u0444\u0443\u043d\u043a\u0446\u0438\u044f notify_observer     \"\"\"      def __init__(self, name):         super().__init__()         self.name = name         self.params = {\"temperature\": 0.0, \"heartrate\": 0.0}      def set_value(self, measure_type, val):         if measure_type in self.params:             self.params[measure_type] = val             self.notify_observer()         else:             print(\"\u0422\u0430\u043a\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043d\u0435\u0442\")      def get_value(self, measure_type):         if measure_type in self.params:             return self.params[measure_type]         else:             return None<\/code><\/pre>\n<pre><code class=\"python\">class HeartbeatMonitor(AbstractObserver):     \"\"\"         \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u043f\u0443\u043b\u044c\u0441\u0430 - \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0443\u043b\u044c\u0441\u0430         \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442      \"\"\"      def __init__(self):         super().__init__()      def update(self, tt):         if type(tt).__name__ == 'Patient':             hr = tt.get_value(\"heartrate\")             if hr &gt; 120:                 print(\"\u041f\u0443\u043b\u044c\u0441 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u044b\u0441\u0442\u0440\u044b\u0439: \" + str(hr))             elif hr &lt; 35:                 print(\"\u041f\u0443\u043b\u044c\u0441 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439:  \" + str(hr))             else:                 print(\"\u041f\u0443\u043b\u044c\u0441 \u0432 \u043d\u043e\u0440\u043c\u0435: \" + str(hr))         else:             pass   class Thermometer(AbstractObserver):     \"\"\"         \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b - \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b         \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442     \"\"\"      def __init__(self):         super().__init__()      def update(self, tt):         if type(tt).__name__ == 'Patient':             temp = tt.get_value(\"temperature\")             if temp &gt; 37.8:                 print(\"\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430: \" + str(temp))             elif temp &lt; 35.0:                 print(\"\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043d\u0438\u0437\u043a\u0430\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430: \" + str(temp))             else:                 print(\"\u0422\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0432 \u043d\u043e\u0440\u043c\u0435: \" + str(temp))         else:             pass<\/code><\/pre>\n<pre><code class=\"python\">import time   if __name__ == \"__main__\":     sub = Patient(\"\u041a\u0438\u0440\u0438\u043b\u043b\")     obs1 = Thermometer()     obs2 = HeartbeatMonitor()      for i in range(15):         time.sleep(1)         print(\"====== \u0428\u0430\u0433 {} =======\".format(i + 1))          if i == 3:             sub.add_obs(obs1) # \u041d\u0430 \u0442\u0440\u0435\u0442\u044c\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b         elif i == 5:             sub.add_obs(obs2) # \u041d\u0430 \u043f\u044f\u0442\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u043f\u0443\u043b\u044c\u0441\u0430         elif i == 10:             sub.remove_obs(obs1) # \u041d\u0430 \u0434\u0435\u0441\u044f\u0442\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b          if i % 3 == 0:             sub.set_value(\"temperature\", 35.5 + 0.5 * i)         elif i % 3 == 1:             sub.set_value(\"heartrate\", 30 + 10 * i)<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fbc\/e31\/031\/fbce310318a659656de88ad3ac86f0f6.png\" width=\"297\" height=\"573\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/fbc\/e31\/031\/fbce310318a659656de88ad3ac86f0f6.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fbc\/e31\/031\/fbce310318a659656de88ad3ac86f0f6.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 (decorator)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u043e\u0432\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u0438\u0431\u043a\u043e\u0439 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043d\u0430\u0448\u0435\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u043a\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0441 \u043a\u0430\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0443\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0441\u044f, \u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e (\u043c\u0435\u043c\u043e\u0438\u0437\u0430\u0446\u0438\u044f).<\/p>\n<pre><code class=\"python\">import sys   def memoize(f):     cache = dict()      def wrapper(x):         if x not in cache:             cache[x] = f(x)         return cache[x]      return wrapper   @memoize def fib(n):     if n &lt;= 1:         return n     else:         return fib(n - 1) + fib(n - 2)   if __name__ == \"__main__\":     sys.setrecursionlimit(2000)     print(fib(750))<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: <\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d24\/9ec\/862\/d249ec862a3968f4aab912d602ce6ca6.png\" width=\"1265\" height=\"22\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/d24\/9ec\/862\/d249ec862a3968f4aab912d602ce6ca6.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d24\/9ec\/862\/d249ec862a3968f4aab912d602ce6ca6.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0430 (abstract factory)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0438\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043e\u0442 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044f \u0438\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.  <\/p>\n<pre><code class=\"python\">class Button:     def draw(self):         raise NotImplementedError   class Checkbox:     def draw(self):         raise NotImplementedError   class WindowsButton(Button):     def draw(self):         return \"Drawing a Windows Button\"   class WindowsCheckbox(Checkbox):     def draw(self):         return \"Drawing a Windows Checkbox\"   class MacOSButton(Button):     def draw(self):         return \"Drawing a MacOS Button\"   class MacOSCheckbox(Checkbox):     def draw(self):         return \"Drawing a MacOS Checkbox\"   class GUIFactory:     def create_button(self):         raise NotImplementedError      def create_checkbox(self):         raise NotImplementedError   class WindowsGUIFactory(GUIFactory):     def create_button(self):         return WindowsButton()      def create_checkbox(self):         return WindowsCheckbox()   class MacOSGUIFactory(GUIFactory):     def create_button(self):         return MacOSButton()      def create_checkbox(self):         return MacOSCheckbox()   def create_ui(factory):     button = factory.create_button()     checkbox = factory.create_checkbox()     return button.draw(), checkbox.draw()   if __name__ == \"__main__\":     windows_factory = WindowsGUIFactory()     windows_button, windows_checkbox = create_ui(windows_factory)     print(f\"Windows UI: {windows_button}, {windows_checkbox}\")      macos_factory = MacOSGUIFactory()     macos_button, macos_checkbox = create_ui(macos_factory)     print(f\"MacOS UI: {macos_button}, {macos_checkbox}\") <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1a2\/5f2\/dfd\/1a25f2dfd33a7fc027123a063c6dd402.png\" width=\"521\" height=\"47\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/1a2\/5f2\/dfd\/1a25f2dfd33a7fc027123a063c6dd402.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1a2\/5f2\/dfd\/1a25f2dfd33a7fc027123a063c6dd402.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0424\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 (factory method)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0430\u043c.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0433\u0438\u0431\u043a\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u044b\u0431\u043e\u0440\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430\u043c.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<pre><code class=\"python\">class Document:     def __init__(self, content):         self.content = content      def render(self):         raise NotImplementedError(\"Subclasses must implement this method\")   class PDFDocument(Document):     def render(self):         return f\"Rendering PDF Document: {self.content}\"   class HTMLDocument(Document):     def render(self):         return f\"Rendering HTML Document: {self.content}\"   class DocumentCreator:     def create_document(self, content):         raise NotImplementedError(\"Subclasses must implement this method\")      def display_document(self, content):         document = self.create_document(content)         print(document.render())   class PDFDocumentCreator(DocumentCreator):     def create_document(self, content):         return PDFDocument(content)   class HTMLDocumentCreator(DocumentCreator):     def create_document(self, content):         return HTMLDocument(content)   if __name__ == \"__main__\":     pdf_creator = PDFDocumentCreator()     pdf_creator.display_document(\"This is a PDF document\")      html_creator = HTMLDocumentCreator()     html_creator.display_document(\"This is an HTML document\") <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3d2\/f29\/bf9\/3d2f29bf983278411ab821728f37d660.png\" width=\"402\" height=\"54\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/3d2\/f29\/bf9\/3d2f29bf983278411ab821728f37d660.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3d2\/f29\/bf9\/3d2f29bf983278411ab821728f37d660.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u041e\u0434\u0438\u043d\u043e\u0447\u043a\u0430 (singleton)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440, \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u044d\u0442\u043e\u043c\u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043a\u0430\u043a \u0431\u044b \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u0438, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">class SingletonClass:     _instance = None       def __new__(cls):         if cls._instance is None:             cls._instance = super(SingletonClass, cls).__new__(cls)         return cls._instance   singleton = SingletonClass() new_singleton = SingletonClass()  print(singleton is new_singleton)  singleton.singl_variable = \"2\" print(new_singleton.singl_variable)<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e74\/de3\/d42\/e74de3d42491060498a18d2d1fca7d9f.png\" width=\"44\" height=\"43\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/e74\/de3\/d42\/e74de3d42491060498a18d2d1fca7d9f.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e74\/de3\/d42\/e74de3d42491060498a18d2d1fca7d9f.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 (command)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0434\u0435\u043b\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438\u043b\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043e\u0442\u043c\u0435\u043d\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\/\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u0430.<\/p>\n<pre><code class=\"python\">from abc import ABC, abstractmethod   class Command(ABC):     @abstractmethod     def execute(self):         pass   class Light:     def turn_on(self):         print(\"The light is ON\")      def turn_off(self):         print(\"The light is OFF\")   class TurnOnCommand(Command):     def __init__(self, light):         self.light = light      def execute(self):         self.light.turn_on()   class TurnOffCommand(Command):     def __init__(self, light):         self.light = light      def execute(self):         self.light.turn_off()   class RemoteControl:     def __init__(self):         self.command = None      def set_command(self, command):         self.command = command      def press_button(self):         if self.command:             self.command.execute()   if __name__ == \"__main__\":     light = Light()     remote = RemoteControl()      turn_on = TurnOnCommand(light)     turn_off = TurnOffCommand(light)      remote.set_command(turn_on)     remote.press_button()      remote.set_command(turn_off)     remote.press_button() <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/620\/14e\/7cf\/62014e7cff41d32987c640eea09bef26.png\" width=\"141\" height=\"46\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/620\/14e\/7cf\/62014e7cff41d32987c640eea09bef26.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/620\/14e\/7cf\/62014e7cff41d32987c640eea09bef26.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0410\u0434\u0430\u043f\u0442\u0435\u0440 (adapter)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043b\u0430\u0441\u0441\u0430 \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043a\u043b\u0438\u0435\u043d\u0442. \u0410\u0434\u0430\u043f\u0442\u0435\u0440 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0443\u044e \u0432 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0438\u0437-\u0437\u0430 \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0441 \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435. \u0412\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432 \u0440\u043e\u043b\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\"># \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442 class NotificationService:     def send_notification(self, message, recipient):         raise NotImplementedError(\"Subclasses must implement this method\")   # \u041a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c class LegacyNotificationSystem:     def send_legacy_notification(self, user_id, text):         print(f\"Legacy system: Sending notification '{text}' to user {user_id}\")   # \u0410\u0434\u0430\u043f\u0442\u0435\u0440 class NotificationAdapter(NotificationService):     def __init__(self, legacy_system):         self.legacy_system = legacy_system      def send_notification(self, message, recipient):         # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442, \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0434\u043b\u044f LegacyNotificationSystem         self.legacy_system.send_legacy_notification(recipient, message)   class Client:     def __init__(self, notification_service):         self.notification_service = notification_service      def send_message(self, message, recipient):         self.notification_service.send_notification(message, recipient)   if __name__ == \"__main__\":     legacy_system = LegacyNotificationSystem()     adapter = NotificationAdapter(legacy_system)      client = Client(adapter)     client.send_message(\"Hello, world!\", \"12345\") <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/58e\/e53\/365\/58ee533654f6ca31fe90d56833b827a7.png\" width=\"526\" height=\"26\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/58e\/e53\/365\/58ee533654f6ca31fe90d56833b827a7.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/58e\/e53\/365\/58ee533654f6ca31fe90d56833b827a7.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0424\u0430\u0441\u0430\u0434 (facade)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a \u0433\u0440\u0443\u043f\u043f\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b.\u041e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0443\u043f\u0440\u043e\u0449\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043d\u0435\u0439.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u043e-\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u0430\u043c Inventory, Payment \u0438 Notification \u0431\u044b\u043b \u0441\u043e\u0431\u0440\u0430\u043d \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441 OrderFacade, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f.<\/p>\n<pre><code class=\"python\">class Inventory:     def check_stock(self, product_id):         print(f\"Checking stock for product {product_id}\")         return True      def update_stock(self, product_id, quantity):         print(f\"Updating stock for product {product_id} by {quantity}\")   class Payment:     def process_payment(self, amount):         print(f\"Processing payment of ${amount}\")         return True   class Notification:     def send_confirmation(self, order_id):         print(f\"Sending confirmation for order {order_id}\")   class OrderFacade:     def __init__(self):         self.inventory = Inventory()         self.payment = Payment()         self.notification = Notification()      def place_order(self, product_id, quantity, amount):         if self.inventory.check_stock(product_id):             if self.payment.process_payment(amount):                 self.inventory.update_stock(product_id, -quantity)                 self.notification.send_confirmation(product_id)                 print(\"Order placed successfully\")             else:                 print(\"Payment processing failed\")         else:             print(\"Product is out of stock\")   if __name__ == \"__main__\":     facade = OrderFacade()     facade.place_order(product_id=1, quantity=1, amount=100) <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7b0\/923\/b90\/7b0923b90698995729977b77a7dc46f9.png\" width=\"282\" height=\"110\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/7b0\/923\/b90\/7b0923b90698995729977b77a7dc46f9.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7b0\/923\/b90\/7b0923b90698995729977b77a7dc46f9.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0428\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 (template method)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0437\u0430\u0434\u0430\u0451\u0442 \u0441\u043a\u0435\u043b\u0435\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435, \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0430\u043c. \u0421\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0448\u0430\u0433\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u0435\u0433\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">class ReportGenerator:      def generate_report(self):         self.collect_data()         self.format_data()         self.generate_header()         self.generate_body()         self.generate_footer()         self.output_report()      def collect_data(self):         raise NotImplementedError(\"Subclasses must implement this method\")      def format_data(self):         raise NotImplementedError(\"Subclasses must implement this method\")      def generate_header(self):         print(\"Generating default header\")      def generate_footer(self):         print(\"Generating default footer\")      def output_report(self):         print(\"Outputting report to console\")   class SalesReportGenerator(ReportGenerator):  # ConcreteClass     def collect_data(self):         print(\"Collecting sales data\")         self.sales_data = [\"Sales 1\", \"Sales 2\", \"Sales 3\"]      def format_data(self):         print(\"Formatting sales data\")         self.formatted_sales_data = \"\\n\".join(self.sales_data)      def generate_header(self):         print(\"Generating Sales Report Header\")      def generate_body(self):         print(\"Generating Sales Report Body\")         print(self.formatted_sales_data)   class PerformanceReportGenerator(ReportGenerator):  # ConcreteClass     def collect_data(self):         print(\"Collecting performance data\")         self.performance_data = [\"Perf 1\", \"Perf 2\", \"Perf 3\"]      def format_data(self):         print(\"Formatting performance data for web output\")         self.formatted_performance_data = \"&lt;br&gt;\".join(self.performance_data)      def generate_body(self):         print(\"Generating Performance Report Body\")         print(self.formatted_performance_data)      def output_report(self):         print(\"Outputting report to web page\")   if __name__ == \"__main__\":     sales_report = SalesReportGenerator()     sales_report.generate_report()      performance_report = PerformanceReportGenerator()     performance_report.generate_report() <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/efa\/dfa\/daf\/efadfadaf7616bd7acc41b81d7c8024e.png\" width=\"349\" height=\"355\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/efa\/dfa\/daf\/efadfadaf7616bd7acc41b81d7c8024e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/efa\/dfa\/daf\/efadfadaf7616bd7acc41b81d7c8024e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440 (iterator)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0438\u044f \u0435\u0451 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043d\u0435 \u0437\u043d\u0430\u044f \u043a\u0430\u043a \u043e\u043d\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: <\/p>\n<pre><code class=\"python\">class NumberIterator:     def __init__(self, numbers):         self._numbers = numbers         self._index = 0      def __iter__(self):         return self      def __next__(self):         if self._index &lt; len(self._numbers):             result = self._numbers[self._index]             self._index += 1             return result         else:             raise StopIteration   numbers = [1, 2, 3, 4, 5] iterator = NumberIterator(numbers)  for number in iterator:     print(number) <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/165\/2ca\/ac5\/1652caac50e1607e666ae6ad74a9de1e.png\" width=\"22\" height=\"109\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/165\/2ca\/ac5\/1652caac50e1607e666ae6ad74a9de1e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/165\/2ca\/ac5\/1652caac50e1607e666ae6ad74a9de1e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u041a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0449\u0438\u043a (composite)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439 &#171;\u0447\u0430\u0441\u0442\u044c\/\u0446\u0435\u043b\u043e\u0435&#187;. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0438 \u0438\u0445 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u043a\u0430\u043a \u0441 \u0435\u0434\u0438\u043d\u044b\u043c \u0446\u0435\u043b\u044b\u043c, \u0442\u0430\u043a \u0438 \u043f\u043e-\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430.<\/p>\n<pre><code class=\"python\">from abc import ABC, abstractmethod   class FileSystem(ABC):     @abstractmethod     def print(self, indent: int = 0) -&gt; None:         pass <\/code><\/pre>\n<pre><code class=\"python\">class File(FileSystem):     def __init__(self, name: str, size: int):         self.name = name         self.size = size      def print(self, indent: int = 0) -&gt; None:         print(\" \" * indent + f\"\u0424\u0430\u0439\u043b: {self.name} (\u0420\u0430\u0437\u043c\u0435\u0440: {self.size} KB)\")<\/code><\/pre>\n<pre><code class=\"python\">class Directory(FileSystem):     def __init__(self, name: str):         self.name = name         self.contents: list = []      def print(self, indent: int = 0) -&gt; None:         print(\" \" * indent + f\"\u041f\u0430\u043f\u043a\u0430: {self.name}\")         for entity in self.contents:             entity.print(indent + 2)      def add_entity(self, entity: FileSystem) -&gt; None:         self.contents.append(entity)      def remove_entity(self, entity: FileSystem) -&gt; None:         if entity in self.contents:             self.contents.remove(entity)<\/code><\/pre>\n<pre><code class=\"python\">def main():     file1 = File(\"file1.txt\", 128)     file2 = File(\"file2.txt\", 1024)     file3 = File(\"file3.txt\", 2048)      dir1 = Directory(\"dir1\")     dir1.add_entity(file1)     dir1.add_entity(file2)      nested_dir = Directory(\"nested_dir\")     nested_dir.add_entity(file3)      dir1.add_entity(nested_dir)      root_dir = Directory(\"root\")     root_dir.add_entity(dir1)     root_dir.add_entity(File(\"root_file.txt\", 256))      root_dir.print()   if __name__ == \"__main__\":     main() <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/862\/d1d\/6e7\/862d1d6e7cd2a6dac3f3f41fe6005549.png\" width=\"326\" height=\"161\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/862\/d1d\/6e7\/862d1d6e7cd2a6dac3f3f41fe6005549.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/862\/d1d\/6e7\/862d1d6e7cd2a6dac3f3f41fe6005549.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (state)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0435\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0412\u043d\u0435\u0448\u043d\u0435 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a, \u0441\u043b\u043e\u0432\u043d\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u043a\u0430\u043a \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0435 \u0432 \u043d\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0440\u0430\u0431\u043e\u0442\u0430 \u043b\u0438\u0444\u0442\u0430 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f: \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u0436, \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u0430\u0436.<\/p>\n<pre><code class=\"python\">from __future__ import annotations from abc import ABC, abstractmethod   class Elevator:     _state = None      def __init__(self, state: State) -&gt; None:         self.setElevator(state)      def setElevator(self, state: State):         self._state = state         self._state.elevator = self      def presentState(self):         print(f\"\u041b\u0438\u0444\u0442 \u043d\u0430 {type(self._state).__name__}\")      def pushDownBtn(self):         self._state.pushDownBtn()      def pushUpBtn(self):         self._state.pushUpBtn()   class State(ABC):     def __init__(self):         self._elevator = None      @property     def elevator(self) -&gt; Elevator:         return self._elevator      @elevator.setter     def elevator(self, elevator: Elevator) -&gt; None:         self._elevator = elevator      @abstractmethod     def pushDownBtn(self) -&gt; None:         pass      @abstractmethod     def pushUpBtn(self) -&gt; None:         pass <\/code><\/pre>\n<pre><code class=\"python\">class FirstFloor(State):      def pushDownBtn(self) -&gt; None:         print(\"\u0423\u0436\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u0442\u0430\u0436\u0435\")      def pushUpBtn(self) -&gt; None:         print(\"\u041b\u0438\u0444\u0442 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u0430\u0436\")         self.elevator.setElevator(SecondFloor())   class SecondFloor(State):      def pushDownBtn(self) -&gt; None:         print(\"\u041b\u0438\u0444\u0442 \u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u0436\")         self.elevator.setElevator(FirstFloor())      def pushUpBtn(self) -&gt; None:         print(\"\u041b\u0438\u0444\u0442 \u0443\u0436\u0435 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u044d\u0442\u0430\u0436\u0435\") <\/code><\/pre>\n<pre><code class=\"python\">if __name__ == \"__main__\":     myElevator = Elevator(FirstFloor())     myElevator.presentState()      myElevator.pushUpBtn()     myElevator.presentState()      myElevator.pushDownBtn()     myElevator.presentState() <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/42f\/1f5\/7ee\/42f1f57ee9dbef3d1b978a3ac7d2ef82.png\" width=\"263\" height=\"114\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/42f\/1f5\/7ee\/42f1f57ee9dbef3d1b978a3ac7d2ef82.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/42f\/1f5\/7ee\/42f1f57ee9dbef3d1b978a3ac7d2ef82.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0417\u0430\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c (proxy)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0443\u0440\u0440\u043e\u0433\u0430\u0442\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u0437\u0430\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">class Image:     def __init__(self, filename):         self.filename = filename         self.image = None  # \u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043e      def display(self):         raise NotImplementedError   class RealImage(Image):     def __init__(self, filename):         super().__init__(filename)         self.load_from_disk()  # \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438      def load_from_disk(self):         print(f\"\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u044e {self.filename} \u0441 \u0434\u0438\u0441\u043a\u0430...\")         self.image = f\"\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e {self.filename}\"         print(f\"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 {self.filename} \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u0430.\")      def display(self):         print(f\"\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0430 {self.image}\")   class ProxyImage(Image):     def __init__(self, filename):         super().__init__(filename)         self.real_image = None  # \u0420\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043e      def display(self):         if self.real_image is None:             self.real_image = RealImage(self.filename)  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438         self.real_image.display()   if __name__ == \"__main__\":     image1 = ProxyImage(\"image1.jpg\")     image2 = ProxyImage(\"image2.png\")      print(\"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0435\u0449\u0451 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b\")      image1.display()  # \u0412\u043e\u0442 \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 image1     image2.display()  # \u0412\u043e\u0442 \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 image2     <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0ce\/150\/793\/0ce150793f99aa28c66bea6e2b009c1c.png\" width=\"295\" height=\"157\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/0ce\/150\/793\/0ce150793f99aa28c66bea6e2b009c1c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0ce\/150\/793\/0ce150793f99aa28c66bea6e2b009c1c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/930094\/\"> https:\/\/habr.com\/ru\/articles\/930094\/<\/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<h2>\u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c (observer)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 &#171;\u043e\u0434\u0438\u043d \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c&#187; \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c. \u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0438 &#8212; \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0430\u0446\u0438\u0435\u043d\u0442 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 \u0438 \u043f\u0443\u043b\u044c\u0441 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0430\u0446\u0438\u0435\u043d\u0442 &#8212; \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b (\u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0438 \u043f\u0443\u043b\u044c\u0441). \u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0438 &#8212; \u0431\u043b\u043e\u043a\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044f\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0442\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<pre><code class=\"python\">class AbstractClass:     \"\"\"         \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:         add_obs - \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f         remove_obs - \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f         notify_observer - \u0440\u0430\u0437\u043e\u0441\u043b\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f\u043c     \"\"\"      def __init__(self):         self.__observers = []      def add_obs(self, observer):         self.__observers.append(observer)      def remove_obs(self, observer):         self.__observers.remove(observer)      def notify_observer(self, *arg):         for i in self.__observers:             i.update(self, *arg)<\/code><\/pre>\n<pre><code class=\"python\">class AbstractObserver:     \"\"\"         \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c         \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f\u043c \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434 update, \u043a\u043e\u0442\u043e\u0440\u044b\u0439      \"\"\"      def __init__(self):         pass      def update(self):         pass<\/code><\/pre>\n<pre><code class=\"python\">class Patient(AbstractClass):     \"\"\"         \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u0430\u0446\u0438\u0435\u043d\u0442 - \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442         \u0444\u0443\u043d\u043a\u0446\u0438\u044f notify_observer     \"\"\"      def __init__(self, name):         super().__init__()         self.name = name         self.params = {\"temperature\": 0.0, \"heartrate\": 0.0}      def set_value(self, measure_type, val):         if measure_type in self.params:             self.params[measure_type] = val             self.notify_observer()         else:             print(\"\u0422\u0430\u043a\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043d\u0435\u0442\")      def get_value(self, measure_type):         if measure_type in self.params:             return self.params[measure_type]         else:             return None<\/code><\/pre>\n<pre><code class=\"python\">class HeartbeatMonitor(AbstractObserver):     \"\"\"         \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u043f\u0443\u043b\u044c\u0441\u0430 - \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0443\u043b\u044c\u0441\u0430         \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442      \"\"\"      def __init__(self):         super().__init__()      def update(self, tt):         if type(tt).__name__ == 'Patient':             hr = tt.get_value(\"heartrate\")             if hr &gt; 120:                 print(\"\u041f\u0443\u043b\u044c\u0441 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u044b\u0441\u0442\u0440\u044b\u0439: \" + str(hr))             elif hr &lt; 35:                 print(\"\u041f\u0443\u043b\u044c\u0441 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439:  \" + str(hr))             else:                 print(\"\u041f\u0443\u043b\u044c\u0441 \u0432 \u043d\u043e\u0440\u043c\u0435: \" + str(hr))         else:             pass   class Thermometer(AbstractObserver):     \"\"\"         \u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b - \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b         \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442     \"\"\"      def __init__(self):         super().__init__()      def update(self, tt):         if type(tt).__name__ == 'Patient':             temp = tt.get_value(\"temperature\")             if temp &gt; 37.8:                 print(\"\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430: \" + str(temp))             elif temp &lt; 35.0:                 print(\"\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043d\u0438\u0437\u043a\u0430\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430: \" + str(temp))             else:                 print(\"\u0422\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0432 \u043d\u043e\u0440\u043c\u0435: \" + str(temp))         else:             pass<\/code><\/pre>\n<pre><code class=\"python\">import time   if __name__ == \"__main__\":     sub = Patient(\"\u041a\u0438\u0440\u0438\u043b\u043b\")     obs1 = Thermometer()     obs2 = HeartbeatMonitor()      for i in range(15):         time.sleep(1)         print(\"====== \u0428\u0430\u0433 {} =======\".format(i + 1))          if i == 3:             sub.add_obs(obs1) # \u041d\u0430 \u0442\u0440\u0435\u0442\u044c\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b         elif i == 5:             sub.add_obs(obs2) # \u041d\u0430 \u043f\u044f\u0442\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u043f\u0443\u043b\u044c\u0441\u0430         elif i == 10:             sub.remove_obs(obs1) # \u041d\u0430 \u0434\u0435\u0441\u044f\u0442\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b          if i % 3 == 0:             sub.set_value(\"temperature\", 35.5 + 0.5 * i)         elif i % 3 == 1:             sub.set_value(\"heartrate\", 30 + 10 * i)<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: <\/p>\n<figure class=\"\"><\/figure>\n<h2>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 (decorator)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u043e\u0432\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u0438\u0431\u043a\u043e\u0439 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043d\u0430\u0448\u0435\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u043a\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0441 \u043a\u0430\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0443\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0441\u044f, \u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e (\u043c\u0435\u043c\u043e\u0438\u0437\u0430\u0446\u0438\u044f).<\/p>\n<pre><code class=\"python\">import sys   def memoize(f):     cache = dict()      def wrapper(x):         if x not in cache:             cache[x] = f(x)         return cache[x]      return wrapper   @memoize def fib(n):     if n &lt;= 1:         return n     else:         return fib(n - 1) + fib(n - 2)   if __name__ == \"__main__\":     sys.setrecursionlimit(2000)     print(fib(750))<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: <\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0430 (abstract factory)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0438\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043e\u0442 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044f \u0438\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.  <\/p>\n<pre><code class=\"python\">class Button:     def draw(self):         raise NotImplementedError   class Checkbox:     def draw(self):         raise NotImplementedError   class WindowsButton(Button):     def draw(self):         return \"Drawing a Windows Button\"   class WindowsCheckbox(Checkbox):     def draw(self):         return \"Drawing a Windows Checkbox\"   class MacOSButton(Button):     def draw(self):         return \"Drawing a MacOS Button\"   class MacOSCheckbox(Checkbox):     def draw(self):         return \"Drawing a MacOS Checkbox\"   class GUIFactory:     def create_button(self):         raise NotImplementedError      def create_checkbox(self):         raise NotImplementedError   class WindowsGUIFactory(GUIFactory):     def create_button(self):         return WindowsButton()      def create_checkbox(self):         return WindowsCheckbox()   class MacOSGUIFactory(GUIFactory):     def create_button(self):         return MacOSButton()      def create_checkbox(self):         return MacOSCheckbox()   def create_ui(factory):     button = factory.create_button()     checkbox = factory.create_checkbox()     return button.draw(), checkbox.draw()   if __name__ == \"__main__\":     windows_factory = WindowsGUIFactory()     windows_button, windows_checkbox = create_ui(windows_factory)     print(f\"Windows UI: {windows_button}, {windows_checkbox}\")      macos_factory = MacOSGUIFactory()     macos_button, macos_checkbox = create_ui(macos_factory)     print(f\"MacOS UI: {macos_button}, {macos_checkbox}\") <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>\u0424\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 (factory method)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0430\u043c.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0433\u0438\u0431\u043a\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u044b\u0431\u043e\u0440\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430\u043c.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<pre><code class=\"python\">class Document:     def __init__(self, content):         self.content = content      def render(self):         raise NotImplementedError(\"Subclasses must implement this method\")   class PDFDocument(Document):     def render(self):         return f\"Rendering PDF Document: {self.content}\"   class HTMLDocument(Document):     def render(self):         return f\"Rendering HTML Document: {self.content}\"   class DocumentCreator:     def create_document(self, content):         raise NotImplementedError(\"Subclasses must implement this method\")      def display_document(self, content):         document = self.create_document(content)         print(document.render())   class PDFDocumentCreator(DocumentCreator):     def create_document(self, content):         return PDFDocument(content)   class HTMLDocumentCreator(DocumentCreator):     def create_document(self, content):         return HTMLDocument(content)   if __name__ == \"__main__\":     pdf_creator = PDFDocumentCreator()     pdf_creator.display_document(\"This is a PDF document\")      html_creator = HTMLDocumentCreator()     html_creator.display_document(\"This is an HTML document\") <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><\/figure>\n<h2>\u041e\u0434\u0438\u043d\u043e\u0447\u043a\u0430 (singleton)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440, \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u044d\u0442\u043e\u043c\u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043a\u0430\u043a \u0431\u044b \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u0438, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">class SingletonClass:     _instance = None       def __new__(cls):         if cls._instance is None:             cls._instance = super(SingletonClass, cls).__new__(cls)         return cls._instance   singleton = SingletonClass() new_singleton = SingletonClass()  print(singleton is new_singleton)  singleton.singl_variable = \"2\" print(new_singleton.singl_variable)<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"\"><\/figure>\n<h2>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 (command)<\/h2>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435: \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0434\u0435\u043b\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438\u043b\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043e\u0442\u043c\u0435\u043d\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\/\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u0430.<\/p>\n<pre><code class=\"python\">from abc import ABC, abstractmethod   class Command(ABC):     @abstractmethod     def execute(self):         pass   class Light:     def turn_on(self):         print(\"The light is ON\")      def turn_off(self):         print(\"The light is OFF\")   class TurnOnCommand(Command):     def __init__(self, light):         self.light = light      def execute(self):<\/code><\/pre>\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-468255","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/468255","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=468255"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/468255\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=468255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=468255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=468255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}