I'm creating a Python application which translates from language A to language B and is accessible through a Flask API. Throughout the translation, several modules can produce multiple messages without aborting the execution, unless a critical error is encountered, i.e. SyntaxError
.
From the design point of view, I will need at least two kinds of messages:
class Message(object):
def __init__(self, message):
self.message = message
class MessageExtended(Message):
def __init__(self, message, lineno, linepos)
super().__init__(message=message)
self.lineno = lineno
self.linepos = linepos
The messages should be stored in different lists, i.e. warnings
and errors
and then returned within a JSON response.
Also I dont want to expose the messages creation to the modules itself. I was more thinking about Factory / Factory method creation.
Should I just create a single instance of let's say MessageBuffer
and then pass it as an argument to the constructors? Or should I make it's methods static
and import it everywhere I need it? Or is there any other approach (design pattern, ...)?
Thanks for suggestions
Aucun commentaire:
Enregistrer un commentaire