File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes program design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "program design" Watch "program design" New topic
Author

program design

Brandon W
Greenhorn

Joined: Jan 22, 2002
Posts: 10
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

Joined: Jan 22, 2002
Posts: 10
testing....
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Brandon W
Greenhorn

Joined: Jan 22, 2002
Posts: 10
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
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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
Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
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.


Never be satisfied with anything less than the best and you will surely pass the test...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: program design