抽象に依存させたコード - 3
`AbstractOutputFile`を継承
class JsonOutputFile(AbstractOutputFile):
title: str
description: str
def output(self, title: str, description: str) -> None:
self.title = title
self.description = description
output: dict[str, str] = {
"title": self.title,
"description": self.description
}
with open("output.json", "w") as f:
json.dump(output, f, indent=4)
# `AbstractOutputFile`を継承
class HtmlOutputFile(AbstractOutputFile):
def output(self, title: str, description: str) -> None:
text: str = "\n"
text += "\n"
text += "" + title + "\n"
text += "\n"
text += "\n"
text += "
" + description + "
\n"
text += "\n"
with open("output.html", mode="w") as f:
f.write(text)
shimakaze-soft 50