Skip to content

Conversation

@JoyBiao
Copy link
Owner

@JoyBiao JoyBiao commented Aug 16, 2021

####Reference Issues
From app/models.py, I find that there are several different kinds of models, like "Latest" model and "Timeline" model. This will make it hard for us to manage our code when we need to make a change. So, I think it will be helpful if some class can create the objects for us.

####What does this implement/fix? Explain your changes.
If we use factory pattern, we can create a factory class and asks it to create class for us, we only need to pass the parameter. For example, in nyt.py, we create 3 Timeline objects, if someday we want to use another model, let say Latest object, we have to change the Timeline to Latest for 3 times. if we use factory, we only need to create a variable named "model_type" and pass it to the constructor of factory class. Every time we want to change the model, we only need to change the "model_type" once.

I added a new ModelFactory class as our factory. This class includes a method create_model(), which will create model instance for us. In nyt.py and jhu.py, I create an insatnce of ModelFactory and asks it to create Timeline instance for us.

####Any other comments?
Thank you!

…app/services/location directory. Change code in jhu.py and nyt.py to use ModelFactory's create_factory() method
…s.py, jhu.py, nyt.py implements the interface DataSourcesInterface in sourcelocations.py. Add BasicLocationService class to implement the LocationService class. LocationService class in __init__.py get a new constructor method. And apply BasicLocationService in app/data/__init__.py
…app/services/location directory. Change code in jhu.py and nyt.py to use ModelFactory's create_factory() method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants