• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

program design

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
When I started programming the assignment, I found I put too much code on the same page. I tried to split the code into files by creating public classes. By doing so, I call the external class by creating instance. Am I in the right approach?
However, when I tried to create another class for creating the panel of a JTable together with a button which tells the program to go to the next panel, I need to create another instance from the Jtable class to call back to the main class to navigate to the next panel. This approach looks strange to me. Also, although clicking the button on the Jtable panel can trigger an event, it goes to the wrong panel. Any recommedation is highly appreciated.
[ January 31, 2002: Message edited by: Brandon W ]
 
Brandon W
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
testing....
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

By doing so, I call the external class by creating instance. Am I in the right approach?


Well yes you will have plenty of public classes. That's what is a benefit of OOP.
As far as having to recreate an instance of your JTable because you switch panels. You will want to relook at where you create your instance, whether you want to pass the reference of that JTable to the next class, so that that class does not have to create a seperate/different instance of the JTable, which means that they both have no clue as to the others existance.

This approach looks strange to me.


I found that whenever I said that, I needed to rewrite that part. You need to trust your instincts in those areas.
I hope that helps a bit for you. I wish I had a good link for you to go to that explains designing OOP applications. But I don't know of any sorry. Except maybe some of the forums here. I think there is an OOP forum at Javaranch
Mark
 
Brandon W
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
Thanks for your advice. Actually, beside creating public class, what other way will you try to reduce the size of a program file?
Brandon
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way I found was to make sure you were using the correct Java API class.
For instance, the collections classes. If I used say a Vector, and it took me 10 lines of code to find a matching Object in a Vector, and then changed it to a HashSet and found that that same code was only 1 line. That's using the correct class.
Always make methods do one thing and one thing only. If you feel that a method is becoming too large, look to see if it is trying to do more than one thing. By spliting this out, you will find that the new method might be able to be called from another method that needs that same functionality, so there you have the code in one place. and It is more readable.
Hope that helps.
Mark
 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While creating the classes, before declaring them as public you would want to consider the use of them, ie, within a package only or not.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic