Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evertonsavio/python-factory-serializer
Python OOP - Implementing a abstract factory pattern on classes that instatiate a JSON, XML or other implemented Serializer
https://github.com/evertonsavio/python-factory-serializer
fact oop py solid
Last synced: about 2 months ago
JSON representation
Python OOP - Implementing a abstract factory pattern on classes that instatiate a JSON, XML or other implemented Serializer
- Host: GitHub
- URL: https://github.com/evertonsavio/python-factory-serializer
- Owner: evertonsavio
- Created: 2024-04-07T21:23:45.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-04-11T19:40:39.000Z (9 months ago)
- Last Synced: 2024-10-15T03:21:45.289Z (3 months ago)
- Topics: fact, oop, py, solid
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Solid Abstract Factory
This repository demonstrates the implementation of an Abstract Factory in Python.
Under [project/models](https://github.com/evertonsavio/python-factory-serializer/tree/master/project/models) we have a class called `Song.py` that inherits Serializable.py
This allows an instance of `Song.py` being able to serialize itself choosing a FormatType like JSON or XML. You can check this on [main.py](https://github.com/evertonsavio/python-factory-serializer/blob/master/main.py).For implementing a new format using this code we only need to add our new format implementation file under [serializers](https://github.com/evertonsavio/python-factory-serializer/tree/master/serializer/serializers/impl) and register it on [registers.py](https://github.com/evertonsavio/python-factory-serializer/blob/master/serializer/constants/registers.py). That's it, all your model classes that inherits [Serializable.py](https://github.com/evertonsavio/python-factory-serializer/blob/master/serializer/Serializable.py) now can serialize itself to the new format.
We don't need to change anything on the class factories or on the core implementation. Check this PR for more information on how this can be done: [PR](https://github.com/evertonsavio/python-factory-serializer/pull/1)## Python
1. Create your environment:
```commandline
python -m venv .venv
```
2. Activate your environment
```commandline
. ./.venv/Scripts/activate
.\venv\Scripts> . activate
```
3. install your dependencies
```commandline
pip install -r ./requirements.txt
```
4. Run project
```commandline
python main.py
```
5. Deactivate Environment
```commandline
deactivate
```
### Development
```
pip install PyYAML
pip freeze > requirements.txt
```