
# Component class
class Graphic: 

	def __init__(self):
		self._identifier = None
		self._parent = None
		self._specifications = None
		self._children = None

	def getComposite(self):
		'''
		Default to None for leaves, override in Composite class
		'''
		return None

	def addParent(self, parent):
		self._parent = parent

	def removeParent(self):
		self._parent = None

	def addChild(self, child):
		'''
		Check that self is not a leaf.
		'''
		if self.getComposite() or self.getComposite() == set():
			self._children.add(child)
			child.addParent(self)

	def removeChild(self, child):
		'''
		Check that self is not a leaf.
		'''
		if self.getComposite():
			self._children.discard(child)
			child.removeParent()

	def printSpecifications(self, indent):
		'''
		Default for leaf
		'''
		print(indent*'\t' + self._identifier + ': ' + str(self._specifications))


# composite class
class Picture(Graphic):

	def __init__(self):
		self._identifier = 'Picture'
		self._children = set()


	def getComposite(self):
		'''
		Override base class method which returns None
		'''
		return self._children


	def printSpecifications(self, indent):
		'''
		Override base class
		'''
		print(indent*'\t' + 'In picture:')
		for child in self._children:
			child.printSpecifications(indent+1)


# leaf classes
class Rectangle(Graphic):
	def __init__(self, given_width, given_length):
		self._identifier = 'Rectangle'
		self._specifications = {'width': given_width, 'length': given_length}


class Circle(Graphic):
	def __init__(self, given_radius):
		self._identifier = 'Circle'
		self._specifications = {'radius': given_radius}


class Text(Graphic):
	def __init__(self, given_text, given_size):
		self._identifier = 'Text'
		self._specifications = {'text': given_text, 'size': given_size}




# main function
def main():
	rect = Rectangle(2,3)
	circ = Circle(5)
	text1 = Text('hi', 3)

	innerPic = Picture()
	innerPic.addChild(rect)
	innerPic.addChild(text1)

	mainPic = Picture()
	mainPic.addChild(innerPic)
	mainPic.addChild(circ)

	mainPic.printSpecifications(0)


if __name__ == "__main__":
    main()

