I have a tricky python structure issue that I can't quite wrap my head around.
Reading in large files is being pulled out of our application code and into its own package. It used to be that one class, lets call it Object, would be used to access file properties, and be passed around our Application. So Application package would call Object.datetime, but now would have to call Object.file_handler.datetime. So I have a few options:
For every property in
FileHandler, create a property inObjectthat just references thefile_handlerobject. So inObjectdo:@property def datetime(self): return self.file_handler.datetimeThis looks really gross because there are dozens of properties/functions, and it's super tight coupling. This is our current solution.
Find a way to copy those functions/properties automatically. Something like:
for property in self.file_handler: create self.property with value self.file_handler.propertyDue to the size of files this MUST be a reference and not a memory copy.
Go through the application and replace every call to
self.object.propertywithself.object.file_handler.property. SinceApplicationis production level code, this is a big ask. It could break other things that we haven't touched in a while (unit tests exist but they're not great).Restructure everything.
FileHandlermust be in a different package, and I don't want to copy/paste the functionality intoApplication. I can't haveObjectextendFileHandlerbecauseObjectrepresentsFileHandlerat one instance in time (it makes my head hurt; basicallyObjectis anApplicationinstance and there are multipleApplications run perFileHandlerobject;FileHandlerobjects are passed toApplicationthrough an iterator). I needObjectbecauseFileHandlercan't implementApplicationfeatures - they should have been two classes in the first place. If someone is interested in this let me know and I can provide more structural details, but I'm leaning towards a hacky one-off solution.
This is a software design problem that I can't seem to crack. I recognize that our code is fragile and not well designed/tested, but it is what it is (most of it predates me, and this isn't a Software Engineering team - mostly math/physics people). Does anyone have guidance? Option 2 is my favorite but I can't find code to make it work.