Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Created March 16, 2018 01:04
Show Gist options
  • Save jordanhudgens/63b280d6ac3799b0969d5daac0ccc49a to your computer and use it in GitHub Desktop.
Save jordanhudgens/63b280d6ac3799b0969d5daac0ccc49a to your computer and use it in GitHub Desktop.
class Html:
def __init__(self, content):
self.content = content
def render(self):
raise NotImplementedError("Subclass must implement render method")
class Heading(Html):
def render(self):
return f'<h1>{self.content}</h1>'
class Div(Html):
def render(self):
return f'<div>{self.content}</div>'
tags = [Div('Some content'), Heading('My Amazing Heading'), Div('Another div')]
for tag in tags:
print(str(tag) + ': ' + tag.render())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment