Results 1 to 6 of 6
  1. #1
    Sajuuk is offline Member
    Join Date
    Jul 2016
    Posts
    3
    Rep Power
    0

    Question Java OOP vs Non-OOP - JavaFX Pong - Best design choice?

    What is the best way to design games in JavaFX?
    I have two examples of a Pong game I made...

    Example Num1 has only one class:
    JavaFX_Pong - Where inside of it everything is preformed (launching, keys, animation).

    Example Num2 has three classes:
    Main - Where the main method and application launch
    MyEvent - Where keyboard presses are handled
    MyTimer - Where animation occurs based on time and keypresses

    My initial thought was the Num2 would be significantly cleaner and easier to work with, but I found it quite difficult.
    Being forced to use several getter and setter methods simply becomes a pain!

    Please run and look at the code for the attached two files and let me know of any design decisions you think work best!
    Note: Programs written in BlueJ and Java8, you do not need BlueJ to run them. Simply copy the .java files over to your editor.
    Attached Files Attached Files

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Java OOP vs Non-OOP - JavaFX Pong - Best design choice?

    Getters and setters for objects is the way to go since they hide implementation details. And OO programming typically allows easier maintenance and/or modifications later on. But your getters and setters for static methods seem to be overkill and clutters the code. I tend to think that num1 is more oo than num2 in spite of the single class.

    Regards,
    Jim
    Last edited by jim829; 07-29-2016 at 02:47 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Join Date
    May 2016
    Location
    Brazil
    Posts
    16
    Rep Power
    0

    Default Re: Java OOP vs Non-OOP - JavaFX Pong - Best design choice?

    I would go with an OOP approach focused on the Pong game elements and behaviors as objects and methods, with a main Game object handling the game state machine operation and dispatch of messages.
    Java Programming student. My Java blog in Portuguese at Java Tutorial Nanoverso.

  4. #4
    Sajuuk is offline Member
    Join Date
    Jul 2016
    Posts
    3
    Rep Power
    0

    Default Re: Java OOP vs Non-OOP - JavaFX Pong - Best design choice?

    They are both pretty good OOP because JavaFX already has a Rectangle class, so I don't have to make my own class of it.
    This is really nice because it has many methods that I use (setX, getX, setY, getY, getWidth, getHeight, and intersects).

    I guess my real question is - Do JavaFX developers separate their event and animation classes out or combine them all into one?
    Separating event and animation into their own classes seems like a huge headache for this program.
    Though, in a larger program with hundreds of keyboard and mouse events, it would be really crazy not to have it separated.

    Perhaps JavaFX developers use two classes? One for the main launch and another for Event+Animation?

  5. #5
    Join Date
    May 2016
    Location
    Brazil
    Posts
    16
    Rep Power
    0

    Default Re: Java OOP vs Non-OOP - JavaFX Pong - Best design choice?

    In a old school project for a shooter game I've decided to let the main Game class to handle input events and collision check, but dispatch the desired behavior of drawing itself and movement to each game object like main player, ship enemies and shots. Must be out there some discussion about some design pattern that serves this case better, allowing less complicated project growth.
    Java Programming student. My Java blog in Portuguese at Java Tutorial Nanoverso.

  6. #6
    Sajuuk is offline Member
    Join Date
    Jul 2016
    Posts
    3
    Rep Power
    0

    Default Re: Java OOP vs Non-OOP - JavaFX Pong - Best design choice?

    @Nathan - Ah, interesting. How do you build something like that?

    Let's say we were making a two player Mario platforming game with Mario, Luigi, Goombas, and Koopas.

    Mario and Luigi would have many similar methods, so they could extend a class called Player.
    Goomba and Koopa would have similar AI behavior, so they could extend a class called Enemy.

    Would you place a private class "MyTimer" that extends AnimationTimer inside of each Mario and Luigi for their keyboard presses?
    Is there only a single EventHandler or would you make one EventHandler for each Mario and Luigi?
    Also, where would you put the EventHandler(s)? In a separate class from Mario/Luigi, or make Mario and Luigi implement EventHandler?

    Thank you!

Similar Threads

  1. I need source code for a JavaFX ping pong game
    By TOAA in forum New To Java
    Replies: 3
    Last Post: 06-21-2015, 01:56 AM
  2. JavaFX Book | Learn JavaFX More In Depth
    By SnakeDoc in forum JavaFX
    Replies: 0
    Last Post: 05-17-2013, 11:10 PM
  3. Is Java SE7 a sensible choice
    By mooncookie in forum New To Java
    Replies: 2
    Last Post: 04-07-2012, 09:45 AM
  4. JavaFX Script and JavaFX Mobile
    By levent in forum Java Software
    Replies: 1
    Last Post: 01-27-2010, 04:48 PM
  5. Using java.awt.Choice
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 06:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •