From 407addbd173e5d90e0cd19b5158fe1ebd67e97a2 Mon Sep 17 00:00:00 2001 From: Dohyun Kim <84333692+dohyun97@users.noreply.github.com> Date: Sun, 15 Aug 2021 03:20:28 -0400 Subject: [PATCH 1/2] structural design pattern --- composite.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 composite.py diff --git a/composite.py b/composite.py new file mode 100644 index 00000000..68b80f4e --- /dev/null +++ b/composite.py @@ -0,0 +1,57 @@ +"""app.coordinates.py""" +from abc import ABCMeta, abstractmethod + + +class Location(metaclass=ABCMeta): + + def __init__(self, latitude, longitude): + """implement""" + + def serialize(self): + """implement""" + + def __str__(self): + """implement""" + +class Coordinates(Location): + """ + A position on earth using decimal coordinates (latitude and longitude). + """ + + def __init__(self, latitude, longitude): + self.latitude = latitude + self.longitude = longitude + + + def serialize(self): + """ + Serializes the coordinates into a dict. + + :returns: The serialized coordinates. + :rtype: dict + """ + return {"latitude": self.latitude, "longitude": self.longitude} + + def __str__(self): + return "lat: %s, long: %s" % (self.latitude, self.longitude) + + +class history(Location): + def __init__(self, latitude, longitude): + self.latitude = latitude + self.longitude = longitude + self.hisLocations = [] + + def add(self, hisLocation): + self.hisLocations.append(hisLocation) + self.latitude += hisLocation.latitude + self.longitude += hisLocation.longitude + + + def serialize(self): + for hisLocation in self.hisLocations: + hisLocation.serialize + return {"Total longitude": self.longitude, "Total latitude": self.latitude} + + def __str__(self): + return "lat: %s, long: %s" % (self.latitude, self.longitude) \ No newline at end of file From 02c91d7e985566f219700bfb06407669493e473e Mon Sep 17 00:00:00 2001 From: Dohyun Kim <84333692+dohyun97@users.noreply.github.com> Date: Sun, 15 Aug 2021 23:10:33 -0400 Subject: [PATCH 2/2] Add files via upload