Results 1 to 4 of 4

Thread: Object Oriented

  1. #1
    GraemeH is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default Object Oriented

    Hello.

    could you tell me whether its possible to change the following code so it can be used in an OO way? if so how!?

    do you take main out of the class, but then what goes in main? sorry for these questions i'm new to java!
    Last edited by GraemeH; 05-05-2009 at 09:34 AM.

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Well, it's a pretty contained piece of code, but what I would do is following:
    • It's very bad idea to hardcode paths in a program. Every time the path changes, you have to change the program, recompile , etc. Why not get the path from a sort of properties file (LimeWire.prop?). That way, if the path changes, you can change the property file without recompiling the code. You can also store the regex patterns in that file (same advantage as explained before).
    • Breakout the comparation/search part into a method (or into another class if it can be used by other classes).

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    GraemeH is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default

    thanks for the reply CJSLMAN.
    ave a clue where to put the regex expressions in here!! can anyone help please?
    Last edited by GraemeH; 05-05-2009 at 09:34 AM.

  4. #4
    glhansen is offline Member
    Join Date
    Mar 2009
    Posts
    20
    Rep Power
    0

    Default

    To make it more OOPy you do need to make the code part of a class definition so an object can be instantiated. But then main will look almost stupidly simple, something like
    Java Code:
    public void main(String args[]) {
       LimeWireAnalyserDownloadDat lime = new LimeWireAnalyserDownloadDat();
       lime.doStuff();
    }
    The only class method there is doStuff(). But your example is so straightforward, and it doesn't interact with other objects, that you could put all of the code in the constructor and do without other methods if you wanted to, and it would be automatically run when the object is created. If it interacts with other objects you should have method functions like getValueOne(), setValueOne(), saveWorld(), etc., which let other objects communicate with it and tell it to do stuff.
    Last edited by glhansen; 03-29-2009 at 08:52 PM. Reason: Fix the code brackets.

Similar Threads

  1. Replies: 1
    Last Post: 03-04-2009, 07:14 PM
  2. Object- Oriented guide?
    By sciguy77 in forum New To Java
    Replies: 4
    Last Post: 01-18-2009, 04:33 AM
  3. Is JAVA completely object-oriented???
    By venkateshk in forum New To Java
    Replies: 2
    Last Post: 11-17-2008, 10:17 AM
  4. Oriented language
    By pawankumarom in forum New To Java
    Replies: 1
    Last Post: 09-08-2008, 02:12 PM
  5. Question about java object oriented Language
    By lenny in forum New To Java
    Replies: 3
    Last Post: 07-26-2007, 04:59 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
  •