Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface question  RSS feed

 
Sergio Zuniga
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i want to to use an interface to nofify from one class to another(both classes are unrelated) that a process has finished.
I would like to know if is possible to do that with an interface or if there is a better way to do it.

thanks in advance
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface is a contract that says any implementing class must implement the methods defined in the interface. It can't include any code to actually send and receive messages.

That said, creating an interface to define the notification methods is a good idea. An interface is a nice abstraction. The JDK includes an Observer interface along with an Observable class that might do the job for you. Look into the JavaDoc and see if they'll fit.

Before I learned about Observable/Observer I wrote my own little pub-sub routine - a one-abstract-class-framework. If Observable doesn't work out for you I'd be happy to discuss my code. We usually don't hand out complete solutions in this forum - it's much more fun and educational if you work out the tricky bits yourself. So see what you can get going, post some code, we'll talk some more.
[ April 04, 2005: Message edited by: Stan James ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!