Skip to content

Instantly share code, notes, and snippets.

@Sean-Bradley
Created August 17, 2020 18:21
Show Gist options
  • Save Sean-Bradley/21ecf5a12da9e77ac4b3c01ba0a74b1c to your computer and use it in GitHub Desktop.
Save Sean-Bradley/21ecf5a12da9e77ac4b3c01ba0a74b1c to your computer and use it in GitHub Desktop.
from abc import ABCMeta, abstractmethod
class IGraphic(metaclass=ABCMeta):
@staticmethod
@abstractmethod
def print():
"""print information"""
class Ellipse(IGraphic):
def print(self):
print("Ellipse")
class Circle(IGraphic):
def print(self):
print("Circle")
class CompositeGraphic(IGraphic):
def __init__(self):
self.child_graphics = []
def add(self, graphic):
self.child_graphics.append(graphic)
def print(self):
for g in self.child_graphics:
g.print()
ELLIPSE1 = Ellipse()
CIRCLE1 = Circle()
COMPOSITE1 = CompositeGraphic()
COMPOSITE1.add(ELLIPSE1)
COMPOSITE2 = CompositeGraphic()
COMPOSITE2.add(CIRCLE1)
COMPOSITE2.add(COMPOSITE1)
COMPOSITE2.print()
# ELLIPSE1.print()
# CIRCLE1.print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment