0

For my example:

I do a graphic turtle. So, I have 2 JFrame, one to display the turtle and its movement and some button like "Return", "Change mode". The other one is still a command where user can write commande like "Move forward".

Before I develop, I need to do an UML for the conception.

I will use design pattern MVC and i'm thinking about design pattern Observer for this which will help me to notify thanks to my second JFrame (command interface) to the first JFrame (turtle screen).

I don't know if it's the good idea because I think Observer is when you have dynamic or a lot of View to manage no? (I have only 2 in this example).

Maybe, i'm a little bit confuse with the Observer pattern.

For now, my UML. There are only class Model (not MVC and Observer for now and I'm using design pattern Factory too):

enter image description here

Erased
  • 571
  • 4
  • 10
  • 22
  • Observer pattern is useful for listening to button press events in your UI. Other than that I don't see how the pattern would be useful in the Turtle app. – Mick Mnemonic Sep 29 '17 at 18:44
  • Well, in command line JFrame, user will write command to move the turtle. Press "enter" or a validate button. So, my Command JFrame need to notify to the Display JFrame. It doesn't use the Observer pattern? – Erased Sep 29 '17 at 18:56
  • Better check this post https://stackoverflow.com/questions/13744450/when-should-we-use-observer-and-observable – Ravi Sep 29 '17 at 18:58
  • Mmmh well, so in your link he takes the example of Twitter. In his example Twitter have one observable (The management of tweet) and several observer (users who will see a message posted). In my example, My turtle class is the observable and my 2 JFrame are my observers? But it's fix whereas in Twitter the number of users are dynamic... MMh I don't really know – Erased Sep 29 '17 at 19:02
  • Possible duplicate of [When should we use Observer and Observable](https://stackoverflow.com/questions/13744450/when-should-we-use-observer-and-observable) – qwerty_so Sep 29 '17 at 21:05
  • Well I read it. It says when there are one to many relation between Observer and Observable. So well, my turtle is the observable and my 2 JFrame are observers? But I don't really understand because when I change my command in the CommandLine JFrame. Only the turtle class is modified then it notify the Display Turtle Frame to change: so the CommandLine JFrame doesn't change at all. So I don't need the Observer design pattern? – Erased Sep 30 '17 at 17:07
  • CommandLine is the Frame who notify the model Turtle to change (by a controller), then the model Turtle notify the DisplayTurtle Frame to update its view of the turtle. I will got only 2 frame. and not several. So, Observer is not useful in my case? – Erased Sep 30 '17 at 17:11
  • Nobody is forced to use any pattern at all. Use whatever fits your design. – qwerty_so Oct 01 '17 at 19:35
  • Ok! I will send you what looks my new UML if you want! @ThomasKilian – Erased Oct 01 '17 at 20:27
  • Uhm, what? Just ask a (good) question and we will see what can be done. – qwerty_so Oct 01 '17 at 23:21

0 Answers0