master #12
|
@ -144,7 +144,7 @@ class InvoicePersistence(abc.ABC):
|
|||
The new _InvoicePersistence_ class has an abstract 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
|
||||
class DatabasePersistence(InvoicePersistence):
|
||||
def __init__(self, invoice):
|
||||
|
@ -154,7 +154,7 @@ class DatabasePersistence(InvoicePersistence):
|
|||
def save(self, invoice):
|
||||
print("Save in database ...")
|
||||
```
|
||||
Let's make the same thing with _FilePersistence_ class.
|
||||
Let's do the same thing with _FilePersistence_ class.
|
||||
```python
|
||||
class FilePersistence(InvoicePersistence):
|
||||
def __init__(self, invoice):
|
||||
|
@ -164,3 +164,13 @@ class FilePersistence(InvoicePersistence):
|
|||
def save(self, invoice):
|
||||
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
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
Loading…
Reference in New Issue