Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  please review design  (Read 1265 times)
0 Members and 1 Guest are viewing this topic.
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Posted 2005-12-27 15:46:15 »

I was a bit confused earlier about how to properly connect a GUI to a logic module, and after asking around I was told of 2 common approaches: the MVC model, and a simpler model where you have a Controller that keeps references to your gui objects. I decided to build the latter and was wondering if anyone can look over my simple design and spot anything that I am missing:

Diagram:
http://kommi.com/images/drawing1.jpg

GUI:
The GUI has 3 buttons, 2 text areas, and 1 progress bar.

Controller:
The Controller has references to the 2 text areas and the progress bar so that it can update their content.

Core Logic
The Core Logic returns String data, and also calls a method to update the progress bar

The three buttons call methods in the Controller. The Controller then calls the appropriate method in the Core Logic. Core Logic returns data to the controller, which then later updates the proper text area. Core Logic can also call a method in the Controller to update the progress bar, which then calls the method in GUI to update the bar.

Kommi
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #1 - Posted 2005-12-27 19:03:43 »

I myself use the MVC pattern. I am not sure if the simpler model you describe is really
easier than MVC? Maybe I am missing something?

To answer your question: yes, I think how you describe it is ok. (I never heard about the
"controller" pattern, so I might be wrong).

However, I would advice you to use MVC. The only difference is the following:
The "Core Logic" updates the "Controller" & then the "Controller" updates the "GUI".
In MVC, the "Core Logic" directly updates the "GUI".

I don't quite see why the "Core Logic" has to update the "Controller", it's one more method
you will need to implement which does not do anything more than just update the "GUI".
MVC would be shorter in that case.

Also, look at the diagrams, MVC and your pattern are pretty much the same:
http://www.enode.com/x/markup/tutorial/mvc.html

Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #2 - Posted 2005-12-27 20:37:43 »

Yeah I changed that so the Core Logic just updates the Controller which then updates the value of the registered GUI component. The reason for this is so the Core Logic does not hold any refrences to the GUI, just the Controller. Thanks for the feedback.

Kommi
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr_Light

Senior Member


Medals: 1


shiny.


« Reply #3 - Posted 2005-12-28 13:38:57 »

where are you going to with this design?

if I hear what you say, it has some aspects of the mediator-pattern with a twist of mvc. whats the problem and how is this gonna help?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #4 - Posted 2005-12-28 15:31:02 »

My intial confusion was just how to properly attach a GUI to a Core Logic module that I built. I did want the ability to extensively modify the GUI or plug in a different one, without modding the Core Logic. Also, the Core Logic was suppose to return data to the GUI. I kind of figured that having the Core Logic hold a ref to the GUI and the GUI holding a ref to the Core Logic was bad design.

Kommi
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #5 - Posted 2005-12-28 19:17:54 »

Yes, that's good! Whatever you do for the "Core Logic", keep it separate from the GUI. The "Core Logic" should know nothing about the GUI.

However, the GUI holds an instance of the "Core Logic". You can update the GUI in two ways:
-Poll the "Core Logic" e.g. every 50ms  and update the view if something changed (->not so good lot of overhead)
-Push method:
  1. Add to "Core Logic":
        addChangeListener(...)
        removeChangeListener(...)
        fireChange(...)
     Changes are sent from the "Core Logic" to all registered listeners.
  2. Register the GUI as listener for changes in the "Core Logic"

1. and 2. keep GUI and "core logic" separate: MVC pattern

Offline Mr_Light

Senior Member


Medals: 1


shiny.


« Reply #6 - Posted 2005-12-28 20:26:49 »

I did want the ability to extensively modify the GUI or plug in a different one
to what extend? change the viewtype? annaloge meter or other graphical representation vs plain number. Change the look? colors,design of the graphical representation(older looking meter) Placement? gobal as well as how components are lined out how much power does the user need?

I kind of figured that having the Core Logic hold a ref to the GUI and the GUI holding a ref to the Core Logic was bad design.
  mind you for data to be displayed there has to be a reference somehow, the aspect is more if its a loose reference or a fixed one. also to implent multiplicity your gonna need 2 classes

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #7 - Posted 2005-12-28 20:38:27 »

Yes the MVC pattern is definatly the way to go, I am seeing that more and more now.

Kommi
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #8 - Posted 2005-12-29 20:10:15 »

Yes, that's good! Whatever you do for the "Core Logic", keep it separate from the GUI. The "Core Logic" should know nothing about the GUI.

However, the GUI holds an instance of the "Core Logic". You can update the GUI in two ways:
-Poll the "Core Logic" e.g. every 50ms  and update the view if something changed (->not so good lot of overhead)
-Push method:
  1. Add to "Core Logic":
        addChangeListener(...)
        removeChangeListener(...)
        fireChange(...)
     Changes are sent from the "Core Logic" to all registered listeners.
  2. Register the GUI as listener for changes in the "Core Logic"

1. and 2. keep GUI and "core logic" separate: MVC pattern

Cool definatly will give the Listener approach a go

Kommi
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (72 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (43 views)
2014-09-07 01:13:42

Longarmx (27 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!