Results 1 to 2 of 2
  1. #1
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default program structure

    Good evening everyone,
    Please review logic below and state, how, in your opinion, it can be further improved to ALLOW FOR FUTURE GROWTH

    I am facing a rapid increase of use of my program (cool!) and am receiving many requests for new features (still very cool). It is mainly because of this, i had to revisit the original structure and to my horror recornize (oh noes!) that it is not as clear as i hoped it would be.

    What you see below is an approach i hope will not only structure existing code, but also will allow for further plug and play improvements.

    PS: On a completely separate thought, i think i wil start my next application with tis exact excersize. If i had thought of a simple 30 lines like this, prior to diving into actual code, end product would have been clearer at least.

    Thank you everyone!

    1500+ lines of code summarized in 30 below:

    Java Code:
    public static void main(String[] args) {
    	validateAndProcessParameters (args)
    	if (whatAreWeDoing =  files):
    		processFiles(files)
    		writeResults
    		createHTML(ok status)
    	if (whatAreWeDoing =  database):
    		validate user input
    		connect to database
    		write Results
    		createHTML (Ok status)
    	Submit a statistical entry to db showing what we just did
    	Send an email to user with quick update
    }
    
    
    validateAndProcessParameters (args) {
    	checkIfFilesExists(files)
    	checkForDuplicates(some specific args)
    	return whatAreWeDoing
    }
    
    checkIfFilesExists(files) {
    	if all is ok, return ok
    	else createHTML(error status) and exit
    }
    
    createHTML (status) {
    	if status is Ok, create valid HTML, 
    		else create "fail" HTML
    
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    OK, this is way I followed in coding.

    First of all I'm collecting complete requirement. Actually this is quite difficult to do at the beginning. I don't think anyone can do 100% completely at the beginning. And also this is the point messup our design all the time.

    Anyway with the collected data move into design, define that from logic to coding design. Since we are using OO concepts we can have as many as methods basically. Normally my practice is the content of the method, or lines of the method, keep to size of the screen. Normally it's 10-15 lines. Sometimes I feel that it's too much. At the same time, I trying to place all the methods in execution order, then easy to go through the code in later developments.

    More time spend on design pace than coding.

    Added only very critical comments on the code as well. Use code/class header as well, which maintain with all the improvements done to the code with the version number.

Similar Threads

  1. HTMLDocument Structure
    By Gudradain in forum AWT / Swing
    Replies: 0
    Last Post: 01-05-2009, 11:05 AM
  2. while Loop (Repetition) structure.
    By gapeach97 in forum New To Java
    Replies: 9
    Last Post: 12-03-2008, 11:52 PM
  3. Queue data structure
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:35 PM
  4. Use if then else structure, help
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:00 AM
  5. Help with Structure
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 03:27 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
  •