Movie lister naive example
This naive example was taken from Martin Fowler's article about dependency injection and inversion of control: http://www.martinfowler.com/articles/injection.html
Like Martin says:
Like all of my examples it's one of those super-simple examples; small enough to be unreal, but hopefully enough for you to visualize what's going on without falling into the bog of a real example.
While original Martin's MovieLister example was a bit modified here, it
makes sense to provide some description. So, the idea of this example is to
movies library that can be configured to work with different
movie databases (csv, sqlite, etc...) and provide 2 main features:
- List all movies that were directed by certain person.
- List all movies that were released in certain year.
Also this example contains 3 mini applications that are based on
app_csv.py- list movies by certain criteria from csv file database.
app_db.py- list movies by certain criteria from sqlite database.
app_db_csv.py- list movies by certain criteria from csv file and sqlite databases.
Instructions for running:
python app_csv.py python app_db.py python app_db_csv.py
Full code of example could be found on GitHub.
Movies library structure:
/movies /__init__.py /finders.py /listers.py /models.py
.. literalinclude:: ../../examples/miniapps/movie_lister/movies/__init__.py :language: python :linenos:
Example application structure:
/example /__init__.py /db.py /main.py
.. literalinclude:: ../../examples/miniapps/movie_lister/example/main.py :language: python :linenos:
.. literalinclude:: ../../examples/miniapps/movie_lister/example/db.py :language: python :linenos:
.. literalinclude:: ../../examples/miniapps/movie_lister/app_csv.py :language: python :linenos:
.. literalinclude:: ../../examples/miniapps/movie_lister/app_db.py :language: python :linenos:
Csv and database application
.. literalinclude:: ../../examples/miniapps/movie_lister/app_db_csv.py :language: python :linenos: