Thinking about the overall architecture of the application logic:
Current status: The
model contains all
resources that are used at runtime.
factory you register a
builder which is used to create a resource via the factory. Every time the factory creates a resource, it adds the resource to the model. That means the factory knows about the model and keeps a reference to it.
The resources can be versioned. Each version of a resource is a child of a base item in the model, and the model is designed like a 2-level tree. The 1st level contains the base resource and the 2nd level all versions of it. The model item of the base resource always points to the first child, e.g. the latest version.
Now to the question: What if you want to create a new version of a resource at runtime? These are some options to initiate the workflow:
- Create a resource via the factory. Be sure that the new resource is added to the model. This is easy if the factory knows about the model. But is this good design?
- Call a method from the model that adds a new version of an existing resource. But for this to work, the model needs to know about the factory, which is not appropriate I think. And maybe the factory already knows about the model (see option 1). From my point of view this design smells.
- Call a method from the resource in order to create a new version of itself. Again this is not appropriate I think, because how is ensured that the model knows about the new resource? The resource should not know that the model even exists.
Please share your thoughts about the right place for a method to create a new version. Is one option more commonly used than another? Are there other more popular options?