Applied The State Pattern to the getLatest() method
I applied The State Pattern to the project's getLatest() method. State Pattern lets us treat the package as if it were a state machine, and react to the transition between certain state.
How?
First to implement state machines, I imported the state_machine package to the project, and updated requirements.txt accordingly. Since getLatest() is a method that contains important information about the total confirmed cases, deaths, and recoveries, I created a two states (start_state, latest_data_state) and two transitions to transition between the states (transition_to_latest_data_state, transition_to_start_state). Now, whenever, latest_data_state is reached, getLatest() is called, and _mostRecentData holds the data fetched.
To return the data held by _mostRecentData, I created a method getMostRecentData().
Does this modification change the behaviour of the project?
Yes; to transition between the states and to access the latest COVID-19 data, I have updated the latest.py file (in examples directory) with the new method of using the package. The new example code is properly commented.
Applied The State Pattern to the
getLatest()
methodI applied The State Pattern to the project's getLatest() method. State Pattern lets us treat the package as if it were a state machine, and react to the transition between certain state.
How?
First to implement state machines, I imported the
state_machine
package to the project, and updatedrequirements.txt
accordingly. SincegetLatest()
is a method that contains important information about the total confirmed cases, deaths, and recoveries, I created a two states (start_state
,latest_data_state
) and two transitions to transition between the states (transition_to_latest_data_state
,transition_to_start_state
). Now, whenever,latest_data_state
is reached,getLatest()
is called, and_mostRecentData
holds the data fetched. To return the data held by_mostRecentData
, I created a methodgetMostRecentData()
.Does this modification change the behaviour of the project?
Yes; to transition between the states and to access the latest COVID-19 data, I have updated the
latest.py
file (inexamples
directory) with the new method of using the package. The new example code is properly commented.