Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: SOLID Principles clarification and help with Classes and Methods

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation SOLID Principles clarification and help with Classes and Methods

    I'm very new to Java and i'm struggling a little with a project we've been set. I have to make a TicTacToe game, and it must contain 5 classes only : a driver class, GUI class, an abstract class for a computer player (randomly chooses between two strategies) which is extended to two classes of a Strategic computer class and a dumb computer class.

    Everyone has different views on what should be on each class so I wanted a clarification.

    My "driver" class includes the main method calling on the GUI class. And my GUI class consists of all GUI components, and the computer classes containing all the computer moves. I wanted to know where I would put all codes regarding to checking for a winning combination and invoking the computer moves?

    Some say in the GUI class but some argue that this will be going against the SOLID principles. Then some say it should be in the driver class? But I am little unsure as to how I would make my driver class interact to check winning moves?

  2. #2
    Member
    Join Date
    Dec 2013
    Location
    Honolulu
    Posts
    83
    Thanks
    1
    Thanked 4 Times in 2 Posts

    Default Re: SOLID Principles clarification and help with Classes and Methods

    Would this game be on an applet? Whichever class has the main method to compare possible "known" combinations before you write it.

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    93
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: SOLID Principles clarification and help with Classes and Methods

    My "driver" class includes the main method calling on the GUI class. And my GUI class consists of all GUI components, and the computer classes containing all the computer moves.
    That sounds like a good modular design to start with. Everybody has a clear and well-defined role so far. So your question then is, which class should be responsible for orchestrating everything together? Some class that will become the program's brain, keeping track of the entire state of the game and telling the other parts what to do and when (but not how, that's their business).

    Those who say the GUI could have this logic are technically correct for very small applications like this, but those who say that would go against "solid" design principles are also correct and I believe even more so. It gets really subjective down in the details, but if I'm making a program that's going to get pretty big, I've always found it helpful to put most of the core logic somewhere other than in the GUI, and use the GUI programmatically as "a tool" rather than "The Brain."

    So based on "solid" design principles, I would make the driver class the main brain. It should create and "own" the players, the 3x3 grid of cells, and the GUI, and should be in charge of orchestrating them all together and deciding what should happen and when amongst them. Kindof like a boss directing employees.

Similar Threads

  1. Exchanging between classes and methods
    By Elyril in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 15th, 2014, 06:00 AM
  2. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  3. Methods In Different Classes
    By Khadafi in forum Java Theory & Questions
    Replies: 2
    Last Post: January 11th, 2012, 06:38 PM
  4. [SOLVED] Calling methods from other classes
    By knightknight in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 7th, 2011, 06:16 PM
  5. classes and methods??
    By paddy1 in forum Member Introductions
    Replies: 1
    Last Post: May 20th, 2011, 09:02 AM