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 ea82234..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 HttpService is the low-level +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') """ 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. 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) +