Reputation: 607
I have a tightly coupled app that I am rewriting. The data model is stored in a class library currently exposing all objects as public. There are several UI components which operate on the various objects. The main window has a routine for generating a report by looping through the base classes stored in the model and adding relevant pages based on object type.
My intention is to implement the factory pattern so the UI only knows about an interface. I will then keep objects in the model as private. But this means I to have push reporting into the model and expose a GetPages() method in the interface for compiling the report. Each concrete object will supply their own part of the report.
I would rather the model not have knowledge of how it is reported. How can I work this?
Upvotes: 0
Views: 51
Reputation: 7525
You can follow DDD/messaging/event stream practices and make any possible reports you need from a stream of events your domain model produces. It eliminates coupling between your model and the reporting system completely. I would suggest this as a way to go.
Otherwise you will have to expose your object to something that knows how to build reports. I wouldn't make it as a responsibility of the UI. You can build some additional logic (application service?) that will "visit" your model and produce some data that can be used by the UI for reporting. But you understand that in this case you always will have coupling between your model and something that sits on top and interrogates it for reporting purposes.
Upvotes: 1