From 9ffd682b8db1f1928efca0504a3622a1ca8f317e Mon Sep 17 00:00:00 2001 From: Muhammad Karim Date: Wed, 24 Jun 2020 08:36:10 +1000 Subject: [PATCH 1/3] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1b9e0be --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Muhammad Karim + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 7b9954ad864f0a643651e9d2541b7e5664e51cb6 Mon Sep 17 00:00:00 2001 From: Muhammad Karim Date: Wed, 24 Jun 2020 01:29:38 +0000 Subject: [PATCH 2/3] GitBook: [master] 2 pages modified --- README.md | 15 +++++++++------ SUMMARY.md | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 SUMMARY.md diff --git a/README.md b/README.md index fe9302d..8e302e2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # solid.python -#### [SOLID Principles](https://en.wikipedia.org/wiki/SOLID) explained in Python with examples. +## [SOLID Principles](https://en.wikipedia.org/wiki/SOLID) explained in Python with examples. + +* [Single Responsibility Principle](https://github.com/heykarimoff/solid.python/blob/master/1.srp.py) +* [Open/Closed Principle](https://github.com/heykarimoff/solid.python/blob/master/2.ocp.py) +* [Liskov Substitution Principle](https://github.com/heykarimoff/solid.python/blob/master/3.lsp.py) +* [Interface Segregation Principle](https://github.com/heykarimoff/solid.python/blob/master/4.isp.py) +* [Dependency Inversion Principle](https://github.com/heykarimoff/solid.python/blob/master/5.dip.py) + + -- [Single Responsibility Principle](https://github.com/heykarimoff/solid.python/blob/master/1.srp.py) -- [Open/Closed Principle](https://github.com/heykarimoff/solid.python/blob/master/2.ocp.py) -- [Liskov Substitution Principle](https://github.com/heykarimoff/solid.python/blob/master/3.lsp.py) -- [Interface Segregation Principle](https://github.com/heykarimoff/solid.python/blob/master/4.isp.py) -- [Dependency Inversion Principle](https://github.com/heykarimoff/solid.python/blob/master/5.dip.py) diff --git a/SUMMARY.md b/SUMMARY.md new file mode 100644 index 0000000..17d1eca --- /dev/null +++ b/SUMMARY.md @@ -0,0 +1,4 @@ +# Table of contents + +* [solid.python](README.md) + From 8a0ca44217014202094437ef6b8fd73b2e55dcea Mon Sep 17 00:00:00 2001 From: kimo722504 Date: Wed, 9 Dec 2020 23:25:57 +0900 Subject: [PATCH 3/3] Modify minor typo and type hint --- 1.srp.py | 6 +++--- 5.dip.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/1.srp.py b/1.srp.py index cd27e8b..fda52a2 100644 --- a/1.srp.py +++ b/1.srp.py @@ -44,9 +44,9 @@ def save(self, animal: Animal): class Animal: def __init__(self, name: str): - self.name = name + self.name = name - def get_name(self): + def get_name(self) -> str: pass @@ -75,7 +75,7 @@ def __init__(self, name: str): self.name = name self.db = AnimalDB() - def get_name(self): + def get_name(self) -> str: return self.name def get(self, id): diff --git a/5.dip.py b/5.dip.py index fb3182e..adc6e4f 100644 --- a/5.dip.py +++ b/5.dip.py @@ -22,13 +22,13 @@ def __init__(self, xml_http_service: XMLHttpService): def get(self, url: str, options: dict): self.xml_http_service.request(url, 'GET') - def post(self, url, options: dict): + def post(self, url: str, options: dict): self.xml_http_service.request(url, 'POST') """ Here, Http is the high-level component whereas XMLHttpService is the low-level component. This design violates DIP A: High-level modules should not depend on -low-level level modules. It should depend upon its abstraction. +low-level modules. It should depend upon its abstraction. Ths Http class is forced to depend upon the XMLHttpService class. If we were to change the Http connection service, maybe we want to connect to the internet @@ -56,7 +56,7 @@ def __init__(self, http_connection: Connection): def get(self, url: str, options: dict): self.http_connection.request(url, 'GET') - def post(self, url, options: dict): + def post(self, url: str, options: dict): self.http_connection.request(url, 'POST') """