Search code examples
design-patternsobserver-pattern

Is it OK for a class to be observable and an observer?


Had a code smell moment and couldn't decided if its OK for a class to be Observable and also an Observer, so thought I'd post here.

class ObservableAndObserver extends Observable implements Observer {

 // Class is ofcourse registering and receving notifcations on different events
 // effectly actving as a middle man. 

 // Is this a pattern in itself?  'middleman-pattern' ??

}

Thoughts? Breaking SRP?


Solution

  • It is technically ok, but you should check that you aren't simply re-transmitting received notifications. If this class is observing class1, and then being observed by class2, try having that class observe class1.