hnc-artur/HNS/json/Shape.py

23 lines
460 B
Python

from abc import abstractmethod
from Enums import ShapeColor
class Shape:
color = ShapeColor.Unknown
@abstractmethod
def area(self):
pass
@abstractmethod
def perimeter(self):
pass
@staticmethod
def convert_to_json(obj):
if isinstance(obj, Shape):
result = obj.__dict__
result['type'] = obj.__class__.__name__
result['color'] = obj.color.name
return result