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: Problem to organize my code in classes

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem to organize my code in classes

    Hi everyone,

    I'm just confused about how to organize my code.

    Basically I have a GUI and other methods to load/write data from/into files.

    For now, I just have one BIG class with everything inside but of course I know it's not that good and I would like to dispatch my code into classes.

    I thought about creating one general class and put the methods that load/write files in that class and create another class just for the GUI. But actually, there are variables that I need in the load/write methods AND in the GUI too.

    So, should I create this extra class for the GUI and make it "extends" the general class (where the main is, and the load/write files methods are) ? I'm not sure about this "extends", I mean if it's the right choice for my situation.

    Can someone help me please ?

    Thank you for your help.


  2. #2
    Junior Member
    Join Date
    Feb 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem to organize my code in classes

    Actually your idea of seperating your classes by GUI and general is correct. I would have the GUI class extend the general class. This just allows you to make changes to the GUI class without having severe errors or changes to the general class and vise versa.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Problem to organize my code in classes

    Its always good to sit down before actually writing the code and think about organization. How you do so is up to you, but its a good idea to try and do so with some concepts in mind, one of which is the concept of code re-use. Its nice to have implementations that can be separated into their own objects and potentially used in aanother project without the dependency of the current project. This is also where 'loose' implementations come into play such as using interfaces and abstract classes, where one class or function doesn't depend upon a defined single class but rather an 'empty' implementation, which facilitates code-reuse. As a more semi-concrete example, one could create a class that represents the file you wish to read/write. All you need to do is create an object of that class, then access the variables you wish
    Last edited by copeg; February 21st, 2010 at 12:16 PM.

Similar Threads

  1. Re: Java Newbie Code Problem
    By erinbasim in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 02:05 AM
  2. [SOLVED] Java Newbie Code Problem
    By lee in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 16th, 2010, 03:05 PM
  3. code needed for the following problem
    By romilc in forum Java Theory & Questions
    Replies: 1
    Last Post: October 11th, 2009, 10:05 AM
  4. connecting two classes?
    By chronoz13 in forum Object Oriented Programming
    Replies: 9
    Last Post: September 1st, 2009, 03:15 PM
  5. [SOLVED] Java program using two classes
    By AZBOY2000 in forum Object Oriented Programming
    Replies: 7
    Last Post: April 21st, 2009, 06:55 AM