hnc-artur/HNS/json/Shape.py

23 lines
460 B
Python
Raw Normal View History

2023-09-24 23:48:30 +02:00
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