Update movie listers example

This commit is contained in:
Roman Mogilatov 2016-04-17 16:19:29 +03:00
parent 860b44f33b
commit bd5ea87ef7
3 changed files with 6 additions and 5 deletions

View File

@ -1,7 +1,7 @@
A naive example of dependency injection in Python
=================================================
Example implementation of dependency injection in Python from Martin Fowler's
Example implementation of dependency injection on Python from Martin Fowler's
article about dependency injection and inversion of control:
http://www.martinfowler.com/articles/injection.html
@ -11,7 +11,8 @@ Instructions for running:
.. code-block:: bash
python _create_db.py
python create_db.py
python app_csv.py
python app_db.py
python app_db_csv.py

View File

@ -17,7 +17,7 @@ class MovieLister(object):
:param movie_finder: Movie finder instance
:type movie_finder: movies.finders.MovieFinder
"""
self.movie_finder = movie_finder
self._movie_finder = movie_finder
def movies_directed_by(self, director):
"""Return list of movies that were directed by certain person.
@ -28,7 +28,7 @@ class MovieLister(object):
:rtype: list[movies.models.Movie]
:return: List of movie instances.
"""
return [movie for movie in self.movie_finder.find_all()
return [movie for movie in self._movie_finder.find_all()
if movie.director == director]
def movies_released_in(self, year):
@ -40,5 +40,5 @@ class MovieLister(object):
:rtype: list[movies.models.Movie]
:return: List of movie instances.
"""
return [movie for movie in self.movie_finder.find_all()
return [movie for movie in self._movie_finder.find_all()
if movie.year == year]