I'm implementing an "engine" class (described below in detail) and I'm not sure what kind of object to use. I've tried doing a little reading on OO patterns but I'm still not sure. I think my question is language agnostic, but fwiw I'm using Python.
I want to make a class that gets some initialization (e.g. a database connection and some other configuration) and then it can be called repeatedly to process bits of info. For the bits of info, I've broken up my logic into a bunch of methods, but now I have a huge calling signature for each method because I need to pass all kinds of things into each one.
The calling code will look something like this:
db = get_a_db_connection()
my_engine = Engine(db, config)
while True:
my_info = get_info_from_somewhere()
my_engine.process_info(my_info)
And the actual Engine class as I have it looks something like this:
class Engine(object):
def __init__(self, db, config):
self.db = db
# Also store the config - it's a little more complicated than
# this but I am abstracting away details that don't seem needed
self.config = config
def process_info(self, info):
foo = self.method1(info)
bar = self.method2(info, foo)
baz = self.method3(info, bar)
qux = self.method4(info, foo, bar, baz)
bla = self.method5(info, bar, baz, qux)
def method1(self, info):
# Do something and return intermediate info
return some_transformation_on_info
# Definitions for method2 - method5 (and more) follow
def method2(self, info, foo):
...
<snip>
It seems like it'd be nice to be able to store those intermediate things as attributes so I don't need to pass them as parameters every time. But it doesn't seem appropriate to store them as attributes since they are specific to a piece of info and not the class as a whole.
Is this a case where I use the factory pattern to create an intermediate object that actually does the processing of info?
method1etc. do into the calling methodprocess_info!