0

I need to create a Playlist, I want to separate code/logic and GUI by using two classes:

  • Playlist (code/logic)
  • PlaylistGui (GUI)

It shall be possible to use the Playlist class standalone, e.g. in some kind of command line environment. The question now is, how would one plug both classes together, when using a GUI? My ideas until now:

  • Expose an observable list from the Playlist class, create a method setItemSource(Playlist source) on the PlaylistGui class
  • Not sure if possible in Java, just know this from .NET: Let Playlist class fire events and let PlaylistGui catch them, should lead to uncoupled code? :-)

Open for new ideas :-) Note I am using Java 7 and JavaFX, though I guess JavaFX doesn't limit possiblities, just extends them.

stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
  • code/logic part should be an API, such that if you replace the GUI by a text interface nothing (except configs maybe) should change in the source code. – UmNyobe Oct 10 '12 at 09:19

3 Answers3

0

Events in Java: http://castever.wordpress.com/2008/07/31/how-to-create-your-own-events-in-java/

Other alternatives are: Java Delegates? or both as separate processes with communication via sockets

Community
  • 1
  • 1
Jacek
  • 87
  • 7
0

Have a look at FXML, Controllers and the SceneBuilder tool.

Puce
  • 37,247
  • 13
  • 80
  • 152
0

I think your basic concept is sound, delegation of responsibility.

I would create an interface of the model, exposing only those methods you think that any basic controller/viewer would want. This means you can change the implementation without effecting any of the components that rely on it.

Listeners are, essentially, just a call back mechanism, where interested parties register themselves (through a common interface) to be notified when something occurs that they are interested.

Take a look at Writing Event Listeners for more information.

I would basic start out with a common library which defines the basic interfaces that all parties would need to know out (such as the PlayList and listeners).

This would allow to design 'n' implementations of the playlist based on your needs

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366