- Are there any techniques for communicating with methods of other components but still keep a "pure" Observer pattern ?
- If yes are they indicated/regularly-used or am I just overcomplicating stuff?
A practical example
Suppose I have an architecture with the following characteristics:
- System is a Word Processor app
- Many components, each with it's own purpose, e.g
- Components modify/observe a single model, the
- The components thus "communicate" via this model observation/modification. The components don't know about each other in any other way.
If I'm not mistaken this is what the Observer Pattern is all about.
So here's one case where there's a problem:
Printerto do it's job it needs some output from component
This is just one edge-case where component
PagePreparatorcan't continuously update the model that is shared between the components because it involves heavy-computation. This involves just a single aspect of
PagePreparator.prepare() // takes a long time to run.
So that's one case where It looks to me that I need to "break away" from this pure Observer setup and just expose the method of
Printer directly and call it explicitly from
Printer. This will couple them explicitly together though.
Are there any techniques for keeping this Observer pattern exclusively and still be able to perform this kind of invocations?
Printerneeds output it sets a flag on the model
updatePageswhich is picked up by
PagePreparatorthen sets the output on the model
Documentwhich is picked up by
Printer's observer which proceeds to do it's job.
Simply "breaking" the pattern and just expose
Printerwhich can then explicitly call it.
Dispatching an event from
Printerwhich is picked up by
PagePreparatorwhich proceeds to set the value on the model
Printerto pick it up.