I’ve been thinking about how to form relationships between entities in my main application and those in modules.
To me, it destroys the encapsulation of a model when I begin to modify it’s code to deine relationships with the core application.
If you guys had an entity in your core application, which you wanted to relate to an entity in the module, how would you go about doing it?
I’ve been considering the idea of extending the base entities from the module in the application, and defining the app specific relationships in there.
What are your thoughts on this?
Yes this is definitely a doozy. As we constantly strive for more decoupled objects how do we deal with this in actuality for modules. If you do inheritance that will be the same as using the object because the dependency is still there no matter what in brittle form. I think the approach I would take with this is to create certain commonality for all modules. A common library of domain objects that I know will have to be shared and coupled to others in other modules. This will at least provide me with needed separation from the rest of the app and modules and I will specifically know that these are shared components.
Again complete decoupling is unattainable. We have to make decisions based on good reasoning of how our maintenance, flexibility and scalability will be affected. Also remember that if we use dependency injection we are a step ahead as we can very easily switch behaviors and structures.
Ortus Solutions, Corp
Thanks for your advice. I have been putting some more thought into this over the past hour or so.
I have been looking at the way you handle the RequestContext decoration within the framework, as I think you could probably utilise some form of decorator pattern along with inheritance to achieve this.
So, the core entity within the module remain the same, but if you want to extend it’s functionality, such as adding relationships, then you establish an extended entity, and you pass the path of this into the module via config, the module then uses your custom class rather than the original.
Does that make sense? And seem like a reasonable approach?
Yes it does. Again just make sure you are not decorating all over the place. That is why maybe having a central or common set of classes could help.
Ortus Solutions, Corp
This would all be quite minimal, I only foresee me needing to extend perhaps one or two of the classes from the module.
I shall work up some proofs of concept tomorrow and see how I get on with it.
I do this at the moment, but it also means that this is a module that is not moveable across applications.
But this doesn’t mean it is not doable, you just have to remember that this is the case.
I have been thinking about this last night and it has been quite tricky.
I'm going to try and experiment with a few different solutions today, see how cleanly I can get things working.