Apply factory pattern. #1
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
####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!