Skip to content

Commit 62e1b42

Browse files
committed
Apply factory method to data
1 parent 1c7e4ae commit 62e1b42

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

app/data/__init__.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
"""app.data"""
2+
from ..services.location import LocationService
23
from ..services.location.csbs import CSBSLocationService
34
from ..services.location.jhu import JhuLocationService
45
from ..services.location.nyt import NYTLocationService
56

6-
# Mapping of services to data-sources.
7+
class dataSourceFactory():
8+
def getDataSource():
9+
return LocationService()
10+
11+
class JhuFactory(dataSourceFactory):
12+
def getDataSource():
13+
return JhuLocationService()
14+
15+
class CSBSFactory(dataSourceFactory):
16+
def getDataSource():
17+
return CSBSLocationService()
18+
19+
class NYTFactory(dataSourceFactory):
20+
def getDataSource():
21+
return NYTLcationService()
22+
23+
24+
# Mapping of factories to data-sources.
725
DATA_SOURCES = {
8-
"jhu": JhuLocationService(),
9-
"csbs": CSBSLocationService(),
10-
"nyt": NYTLocationService(),
26+
"jhu": JhuFactory(),
27+
"csbs": CSBSFactory(),
28+
"nyt": NYTFactory(),
1129
}
1230

13-
1431
def data_source(source):
1532
"""
1633
Retrieves the provided data-source service.
1734
1835
:returns: The service.
1936
:rtype: LocationService
2037
"""
21-
return DATA_SOURCES.get(source.lower())
38+
return DATA_SOURCES.get(source.lower()).getDataSource()

0 commit comments

Comments
 (0)