master #12

Merged
waldek merged 8 commits from :master into master 2022-05-10 16:59:08 +02:00
2 changed files with 12 additions and 2 deletions
Showing only changes of commit a52ad43855 - Show all commits

View File

@ -144,7 +144,7 @@ class InvoicePersistence(abc.ABC):
The new _InvoicePersistence_ class has an abstract method. The new _InvoicePersistence_ class has an abstract method.
So, if a class inherits the _InvoicePersistence_ class, you have to implement the _save_ method. So, if a class inherits the _InvoicePersistence_ class, you have to implement the _save_ method.
And for example, we will create a _DataBasePersistence_ class, and this class inherit the abstract _InvoicePersistence_ class. And for example, we will create a _DataBasePersistence_ class, and this class inherits the abstract _InvoicePersistence_ class.
```python ```python
class DatabasePersistence(InvoicePersistence): class DatabasePersistence(InvoicePersistence):
def __init__(self, invoice): def __init__(self, invoice):
@ -154,7 +154,7 @@ class DatabasePersistence(InvoicePersistence):
def save(self, invoice): def save(self, invoice):
print("Save in database ...") print("Save in database ...")
``` ```
Let's make the same thing with _FilePersistence_ class. Let's do the same thing with _FilePersistence_ class.
```python ```python
class FilePersistence(InvoicePersistence): class FilePersistence(InvoicePersistence):
def __init__(self, invoice): def __init__(self, invoice):
@ -164,3 +164,13 @@ class FilePersistence(InvoicePersistence):
def save(self, invoice): def save(self, invoice):
print("Save to file ...") print("Save to file ...")
``` ```
Ok, we do a lot of things, let's make a UML to represent our class structure.
<center>
<img src="./assets/UML_Solid" alt="" width="400"/>
</center>
That will be more simple to do extension.
### Liskov Substitution Principle

BIN
assets/UML_Solid Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB