Skip to content

Commit 924fbd0

Browse files
author
Vimarsh Patel
committed
Structural pattern: Composite pattern
1 parent 28d753e commit 924fbd0

File tree

3 files changed

+24
-31
lines changed

3 files changed

+24
-31
lines changed

app/location/csbs.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""app.locations.csbs.py"""
22
from . import Location
3-
3+
from . import serialize
44

55
class CSBSLocation(Location):
66
"""
@@ -25,19 +25,7 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat
2525
self.state = state
2626
self.county = county
2727

28-
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
29-
"""
30-
Serializes the location into a dict.
31-
32-
:returns: The serialized location.
33-
:rtype: dict
34-
"""
35-
serialized = super().serialize()
28+
29+
3630

37-
# Update with new fields.
38-
serialized.update(
39-
{"state": self.state, "county": self.county,}
40-
)
4131

42-
# Return the serialized location.
43-
return serialized

app/location/nyt.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""app.locations.nyt.py"""
22
from . import TimelinedLocation
3+
from . import serialize
34

45

56
class NYTLocation(TimelinedLocation):
@@ -14,19 +15,4 @@ def __init__(self, id, state, county, coordinates, last_updated, timelines):
1415
self.state = state
1516
self.county = county
1617

17-
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
18-
"""
19-
Serializes the location into a dict.
20-
21-
:returns: The serialized location.
22-
:rtype: dict
23-
"""
24-
serialized = super().serialize(timelines)
25-
26-
# Update with new fields.
27-
serialized.update(
28-
{"state": self.state, "county": self.county,}
29-
)
30-
31-
# Return the serialized location.
32-
return serialized
18+

app/location/serialize.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
class serialize():
3+
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
4+
"""
5+
Serializes the location into a dict.
6+
7+
:returns: The serialized location.
8+
:rtype: dict
9+
"""
10+
serialized = super().serialize(timelines)
11+
12+
# Update with new fields.
13+
serialized.update(
14+
{"state": self.state, "county": self.county,}
15+
)
16+
17+
# Return the serialized location.
18+
return serialized
19+

0 commit comments

Comments
 (0)