{"id":2767,"date":"2021-11-08T08:00:30","date_gmt":"2021-11-08T08:00:30","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=2767"},"modified":"2025-03-28T03:07:04","modified_gmt":"2025-03-28T03:07:04","slug":"python-open-closed-principle","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/python-oop\/python-open-closed-principle\/","title":{"rendered":"Python Open\u2013closed principle"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn about the open-closed principle to extend the system without directly modifying existing code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-open-closed-principle'>Introduction to the open-closed principle <a href=\"#introduction-to-the-open-closed-principle\" class=\"anchor\" id=\"introduction-to-the-open-closed-principle\" title=\"Anchor for Introduction to the open-closed principle\">#<\/a><\/h2>\n\n\n\n<p>The open-closed principle is one of the five principles in the SOLID principle. The letter O in the SOLID stands for the open-closed principle.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>S<\/strong>&nbsp;&#8211; <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-single-responsibility-principle\/\">Single Responsibility Principle<\/a><\/li>\n\n\n\n<li><strong>O<\/strong>&nbsp;&#8211; Open-closed Principle<\/li>\n\n\n\n<li><strong>L<\/strong>&nbsp;&#8211; <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-liskov-substitution-principle\/\">Liskov Substitution Principle<\/a><\/li>\n\n\n\n<li><strong>I<\/strong>&nbsp;&#8211; <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-interface-segregation-principle\/\">Interface Segregation Principle<\/a><\/li>\n\n\n\n<li><strong>D<\/strong>&nbsp;&#8211; <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-dependency-inversion-principle\/\">Dependency Inversion Principle<\/a><\/li>\n<\/ul>\n\n\n\n<p>The open-closed principle states that a <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-class\/\">class,<\/a> <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-methods\/\">method<\/a>, and <a href=\"https:\/\/www.pythontutorial.net\/python-basics\/python-functions\/\">function<\/a> should be open for extension but closed for modification.<\/p>\n\n\n\n<p>The open-closed principle sounds contradictory.<\/p>\n\n\n\n<p>The purpose of the open-closed principle is to make it easy to add new features (or use cases) to the system without directly modifying the existing code.<\/p>\n\n\n\n<p>Consider the following example:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2021\/11\/Python-Open\u2013closed-principle.svg\" alt=\"\" class=\"wp-image-2869\"\/><\/figure>\n<\/div>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Person<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__init__<\/span><span class=\"hljs-params\">(self, name)<\/span>:<\/span>\n        self.name = name\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__repr__<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">f'Person(name=<span class=\"hljs-subst\">{self.name}<\/span>)'<\/span>\n\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonStorage<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save_to_database<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        print(<span class=\"hljs-string\">f'Save the <span class=\"hljs-subst\">{person}<\/span> to database'<\/span>)\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save_to_json<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        print(<span class=\"hljs-string\">f'Save the <span class=\"hljs-subst\">{person}<\/span> to a JSON file'<\/span>)\n\n\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\n    person = Person(<span class=\"hljs-string\">'John Doe'<\/span>)\n    storage = PersonStorage()\n    storage.save_to_database(person)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pythontutorial.net\/playground\/?q=Y2xhc3MgUGVyc29uOgogICAgZGVmIF9faW5pdF9fKHNlbGYsIG5hbWUpOgogICAgICAgIHNlbGYubmFtZSA9IG5hbWUKCiAgICBkZWYgX19yZXByX18oc2VsZik6CiAgICAgICAgcmV0dXJuIGYnUGVyc29uKG5hbWU9e3NlbGYubmFtZX0pJwoKCmNsYXNzIFBlcnNvblN0b3JhZ2U6CiAgICBkZWYgc2F2ZV90b19kYXRhYmFzZShzZWxmLCBwZXJzb24pOgogICAgICAgIHByaW50KGYnU2F2ZSB0aGUge3BlcnNvbn0gdG8gZGF0YWJhc2UnKQoKICAgIGRlZiBzYXZlX3RvX2pzb24oc2VsZiwgcGVyc29uKToKICAgICAgICBwcmludChmJ1NhdmUgdGhlIHtwZXJzb259IHRvIGEgSlNPTiBmaWxlJykKCgppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgogICAgcGVyc29uID0gUGVyc29uKCdKb2huIERvZScpCiAgICBzdG9yYWdlID0gUGVyc29uU3RvcmFnZSgpCiAgICBzdG9yYWdlLnNhdmVfdG9fZGF0YWJhc2UocGVyc29uKQ%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>In this example, the <code>PersonStorage<\/code> class has two methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>save_to_database()<\/code> method saves a person to the database.<\/li>\n\n\n\n<li>The <code>save_to_json()<\/code> method saves a person to a JSON file.<\/li>\n<\/ul>\n\n\n\n<p>Later, if you want to save the Person&#8217;s object into an XML file, you must modify the <code>PersonStorage<\/code> class. It means that the <code>PersonStorage<\/code> class is not open for extension but modification. Hence, it violates the open-closed principle.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='the-open-closed-principle-example'>The open-closed principle example <a href=\"#the-open-closed-principle-example\" class=\"anchor\" id=\"the-open-closed-principle-example\" title=\"Anchor for The open-closed principle example\">#<\/a><\/h2>\n\n\n\n<p>To make the <code>PersonStorage<\/code> class conforms with the open-closed principle; you need to design the classes so that when you need to save the Person&#8217;s object into a different file format, you don&#8217;t need to modify it.<\/p>\n\n\n\n<p>See the following class diagram:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2021\/11\/Python-Open\u2013closed-principle-exampple.svg\" alt=\"\" class=\"wp-image-2868\"\/><\/figure>\n<\/div>\n\n\n<p>First, define the <code>PersonStorage<\/code> <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-abstract-class\/\">abstract class<\/a> that contains the <code>save()<\/code> abstract method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> abc <span class=\"hljs-keyword\">import<\/span> ABC, abstractmethod\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonStorage<\/span><span class=\"hljs-params\">(ABC)<\/span>:<\/span>\n<span class=\"hljs-meta\">    @abstractmethod<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        <span class=\"hljs-keyword\">pass<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, create two classes <code>PersonDB<\/code> and <code>PersonJSON<\/code> that save the <code>Person<\/code> object into the database and JSON file. These classes inherit from the <code>PersonStorage<\/code> class:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonDB<\/span><span class=\"hljs-params\">(PersonStorage)<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        print(<span class=\"hljs-string\">f'Save the <span class=\"hljs-subst\">{person}<\/span> to database'<\/span>)\n\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonJSON<\/span><span class=\"hljs-params\">(PersonStorage)<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        print(<span class=\"hljs-string\">f'Save the <span class=\"hljs-subst\">{person}<\/span> to a JSON file'<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To save the <code>Person<\/code> object into an XML file, you can define a new class <code>PersonXML<\/code> that inherits from the <code>PersonStorage<\/code> class like this:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2021\/11\/Python-Open\u2013closed-principle-solution.svg\" alt=\"\" class=\"wp-image-2870\"\/><\/figure>\n<\/div>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonXML<\/span><span class=\"hljs-params\">(PersonStorage)<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        print(<span class=\"hljs-string\">f'Save the <span class=\"hljs-subst\">{person}<\/span> to an XML file'<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And you can save the <code>Person<\/code>&#8216;s object into an XML file using the <code>PersonXML<\/code> class:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\n    person = Person(<span class=\"hljs-string\">'John Doe'<\/span>)\n    storage = PersonXML()\n    storage.save(person)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Put it all together:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> abc <span class=\"hljs-keyword\">import<\/span> ABC, abstractmethod\n\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Person<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__init__<\/span><span class=\"hljs-params\">(self, name)<\/span>:<\/span>\n        self.name = name\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__repr__<\/span><span class=\"hljs-params\">(self)<\/span>:<\/span>\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">f'Person(name=<span class=\"hljs-subst\">{self.name}<\/span>)'<\/span>\n\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonStorage<\/span><span class=\"hljs-params\">(ABC)<\/span>:<\/span>\n<span class=\"hljs-meta\">    @abstractmethod<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        <span class=\"hljs-keyword\">pass<\/span>\n\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonDB<\/span><span class=\"hljs-params\">(PersonStorage)<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        print(<span class=\"hljs-string\">f'Save the <span class=\"hljs-subst\">{person}<\/span> to database'<\/span>)\n\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonJSON<\/span><span class=\"hljs-params\">(PersonStorage)<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        print(<span class=\"hljs-string\">f'Save the <span class=\"hljs-subst\">{person}<\/span> to a JSON file'<\/span>)\n\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">PersonXML<\/span><span class=\"hljs-params\">(PersonStorage)<\/span>:<\/span>\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">save<\/span><span class=\"hljs-params\">(self, person)<\/span>:<\/span>\n        print(<span class=\"hljs-string\">f'Save the <span class=\"hljs-subst\">{person}<\/span> to an XML file'<\/span>)\n\n\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\n    person = Person(<span class=\"hljs-string\">'John Doe'<\/span>)\n    storage = PersonXML()\n    storage.save(person)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pythontutorial.net\/playground\/?q=ZnJvbSBhYmMgaW1wb3J0IEFCQywgYWJzdHJhY3RtZXRob2QKCgpjbGFzcyBQZXJzb246CiAgICBkZWYgX19pbml0X18oc2VsZiwgbmFtZSk6CiAgICAgICAgc2VsZi5uYW1lID0gbmFtZQoKICAgIGRlZiBfX3JlcHJfXyhzZWxmKToKICAgICAgICByZXR1cm4gZidQZXJzb24obmFtZT17c2VsZi5uYW1lfSknCgoKY2xhc3MgUGVyc29uU3RvcmFnZShBQkMpOgogICAgQGFic3RyYWN0bWV0aG9kCiAgICBkZWYgc2F2ZShzZWxmLCBwZXJzb24pOgogICAgICAgIHBhc3MKCgpjbGFzcyBQZXJzb25EQihQZXJzb25TdG9yYWdlKToKICAgIGRlZiBzYXZlKHNlbGYsIHBlcnNvbik6CiAgICAgICAgcHJpbnQoZidTYXZlIHRoZSB7cGVyc29ufSB0byBkYXRhYmFzZScpCgoKY2xhc3MgUGVyc29uSlNPTihQZXJzb25TdG9yYWdlKToKICAgIGRlZiBzYXZlKHNlbGYsIHBlcnNvbik6CiAgICAgICAgcHJpbnQoZidTYXZlIHRoZSB7cGVyc29ufSB0byBhIEpTT04gZmlsZScpCgoKY2xhc3MgUGVyc29uWE1MKFBlcnNvblN0b3JhZ2UpOgogICAgZGVmIHNhdmUoc2VsZiwgcGVyc29uKToKICAgICAgICBwcmludChmJ1NhdmUgdGhlIHtwZXJzb259IHRvIGFuIFhNTCBmaWxlJykKCgppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgogICAgcGVyc29uID0gUGVyc29uKCdKb2huIERvZScpCiAgICBzdG9yYWdlID0gUGVyc29uWE1MKCkKICAgIHN0b3JhZ2Uuc2F2ZShwZXJzb24p\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The open-closed principle allows you to design the system so that it is open for extension but closed for modification.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"2767\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-oop\/python-open-closed-principle\/\"\n\t\t\t\tdata-post-title=\"Python Open\u2013closed principle\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"2767\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-oop\/python-open-closed-principle\/\"\n\t\t\t\tdata-post-title=\"Python Open\u2013closed principle\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summary: in this tutorial, you&#8217;ll learn about the open-closed principle to extend the system without directly modifying existing code. Introduction to the open-closed principle # The open-closed principle is one of the five principles in the SOLID principle. The letter O in the SOLID stands for the open-closed principle. The open-closed principle states that a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":417,"menu_order":32,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2767","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/2767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=2767"}],"version-history":[{"count":1,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/2767\/revisions"}],"predecessor-version":[{"id":7172,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/2767\/revisions\/7172"}],"up":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/417"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=2767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}