Skip to content

Commit c3d8c6e

Browse files
authored
Creational Pattern Pull Request)
Why I did it? I have used the factory design pattern to do my creational pattern where i had to provide an interface for creating objects in superclass, but allowing subclasses to alter the type of objects that will be created. How i did it? I created a new interface class for location to implement creational pattern and the interface for location class is missing so i just added an interface class and serialized the location into a dict.
1 parent 6bc1467 commit c3d8c6e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/location/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
from ..utils import countries
44
from ..utils.populations import country_population
55

6+
from abc import abstractmethod, ABCMeta
7+
8+
class ILocation(metaclass=ABCMeta):
9+
10+
@abstractmethod
11+
def serialize():
12+
"""
13+
Serializes the location into a dict.
14+
"""
615

716
# pylint: disable=redefined-builtin,invalid-name
8-
class Location: # pylint: disable=too-many-instance-attributes
17+
class Location(ILocation): # pylint: disable=too-many-instance-attributes
918
"""
1019
A location in the world affected by the coronavirus.
1120
"""
@@ -74,6 +83,7 @@ def serialize(self):
7483
}
7584

7685

86+
7787
class TimelinedLocation(Location):
7888
"""
7989
A location with timelines.

0 commit comments

Comments
 (0)