0

I'm facing a design problem in my Java project. I have a MainWindow frame with several panels which control a microscope in our lab. Each of these panels has some text fields, buttons, etc... to execute a specific task .

I have designed my program following the MVC pattern. Every panel has its own controller. Now I'm facing the design problem of how I should pass data between these controllers without making them dependent on each other.

Two examples:

  1. One panel starts an image acquisition series which takes around 10 min. I wanted to disable the UI controls of all other panels in that time, so the user can't interrupt this series.

  2. As soon as this series finishes I want to display some meta data about this acquisition in another panel (to prepopulate some fields).

My ideas so far:

  • Observer pattern: Having an observer class which listens on all panel-controllers for events which might interest a controller of another panel. This has the disadvantage, that the controllers inheritance is locked to the Observable class. This isn't a problem (yet). I don't really want to make this decision so early on though... hmm... And this observer class will probably vastly grow over time.
  • Notification pattern: Coming from an iOS background NSNotifications came to my mind. But there isn't such thing in Java.

What are your ideas on that problem? Are there other options I'm not aware of? Is my design bad in the first place?

Let me know what you think! Thanks in advance

dennis-tra
  • 1,309
  • 1
  • 14
  • 23

1 Answers1

0

You can make Observable an interface, so there won't be inheritance locking issue. You can also look at the Mediator pattern. Based on the description you provided, it fits your needs.

Gyrotank
  • 153
  • 1
  • 2
  • 9
  • How could I make Observable an interface? The class which extends Observable needs to inherit all the necessary methods to interact with it's observers. I never heard about the Mediator pattern, I'll take a look at that! – dennis-tra Feb 10 '17 at 16:00
  • Well, of course if you use java.util.Observable, which is abstract class, you must use inheritance, but you can always write your own interface with similar role (a nice example can be found [here](http://javarevisited.blogspot.ru/2011/12/observer-design-pattern-java-example.html)). – Gyrotank Feb 10 '17 at 19:45