i'm looking for an elegant solution for my problem.
The situation:
I have some files, that must be imported in a data management system (dms), which stores the files in a folder structure. Because the folders in this dms are not just plain folders, but can have different characteristics, i have a different class per folder type. They all implement my interface IFolderEntity. A IFolderEntity has its own folder name and its parent IFolderEntity.
My problem is:
While processing the files, i do not know the folder structure in advance. The folder path must be determined for each file on a set of custom rules. To get the IFolderEntity for a path, i have build a FolderEntityFactory which returns the IFolderEntity with a set parent for a given path.
But it is possible that a path is requested, where the type of parent folders is not yet specified. Maybe the parent directories will be specified by later files and rules, maybe they will not be specified at all and will just be created as default folders.
It is possible, that values will be set or retrieved or an event will be subscribed, before the final request of the parent IFolderEntity, where a new object could be created.
The files and directories will be imported and created after this processing step. So it just resides as information in the memory till the point, the processing is finished.
Example:
File1 requests folder path /root/directory/subdirectory/filedirectory/
The FolderEntityFactory searches for the parent IFolderEntity with the path /root/directory/subdirectory/. Because this parent path was not requested explicitly previously and so there is until now no IFolderEntity for this parent path. Because of this, a new default IFolderEntity (DefaultFolderEntity) will be built.
Later in the processing of the files, the parent path /root/directory/subdirectory/ will be requested as special type. So instead of a DefaultFolderEntity another class type (CharacteristicsAFolderEntity) have to be built.
In this case, the previous parent folder entity is obsolete and could be replaced.
My current solution
Currently i am using a kind of proxy class, that will buffer all requests until a concrete object would be created. at this point, the proxy just delegates all requests to the concrete object.
The question
I don't think that this is a good solution and that i am barking up the wrong tree. So i am looking out for some recommendations, what a good solution to this problem could look like. Because of the simple fact, that i don't really know what i am searching for, i also couldn't find a solution by myself. If someone could point me in the right direction, that could be enough.
Many thanks in advance for your suggestions
Aucun commentaire:
Enregistrer un commentaire