OOP Design Question

Discussion in 'Java' started by Brenton Fletcher, Nov 19, 2003.

  1. Hello
    I am creating a Java program to search the internet.
    +--------------+ +----------------------------------+
    |GoogleSearcher| |Utilities |
    |extends JFrame| |doSearch(Search s, String browser)|
    +--------------+ +----------------------------------+
    +--------+
    |Search |
    |getURL()|
    +--------+
    ||
    \/
    +------------+
    |GoogleSearch|
    +------------+
    Here is an excerpt from GoogleSearcher:
    when button is clicked, Utilities.doSearch(new GoogleSearch("Hello World!"), "C:\Program Files\Internet Explorer\IEXPLORE.EXE");

    Utilities.doSearch(Search s, String browser) calles Runtime.exec(browser + " \"" + s.getURL() + "\"");
    This opens a new browser window, with the search url as its url.

    What I want is an OOP way to have CompletelyDifferentParamtetersSearcher, YahooSearcher, and FooBarSearcher, perhaps with an abstract base class? The CompletelyDifferentParameterSearcher, for example, might have different options that need to be displayed in the Searcher window, different options to GoogleSearcher, or YahooSearcher. Currently, a new instance of GoogleSearcher is created when the user clicks a button.

    Any help would be appreaciated.
    B.F.
     
    Brenton Fletcher, Nov 19, 2003
    #1
    1. Advertisements

  2. <original text>

    Hello
    I am creating a Java program to search the internet.
    +--------------+ +----------------------------------+
    |GoogleSearcher| |Utilities |
    |extends JFrame| |doSearch(Search s, String browser)|
    +--------------+ +----------------------------------+
    +--------+
    |Search |
    |getURL()|
    +--------+
    ||
    \/
    +------------+
    |GoogleSearch|
    +------------+
    Here is an excerpt from GoogleSearcher:
    when button is clicked, Utilities.doSearch(new GoogleSearch("Hello World!"),
    "C:\Program Files\Internet Explorer\IEXPLORE.EXE");

    Utilities.doSearch(Search s, String browser) calles Runtime.exec(browser + "
    \"" + s.getURL() + "\"");
    This opens a new browser window, with the search url as its url.

    What I want is an OOP way to have CompletelyDifferentParamtetersSearcher,
    YahooSearcher, and FooBarSearcher, perhaps with an abstract base class? The
    CompletelyDifferentParameterSearcher, for example, might have different
    options that need to be displayed in the Searcher window, different options
    to GoogleSearcher, or YahooSearcher. Currently, a new instance of
    GoogleSearcher is created when the user clicks a button.

    </original text>

    Two comments:

    * While your approach to this task [i.e. launcing an external
    browser] is quick and simple, Java does allow you to
    build much of this functionality yourself:

    - Use selected classes in java.net package for I/O
    - Use selected classes in javax.swing for presentation
    [e.g. JEditorPane, etc]

    You could set this task as a challenge, perhaps :) ?

    * Don't overuse inheritance. In your case I'd suggest that
    the different 'searchers' don't differ enough to warrant
    the use of inheritance. Instead, create new classes which
    encapsulate the differences between these items.

    For example, you could create an 'Options' abstract class
    to represent different search options / option types for
    each searcher type e.g.

    abstract class Options { ... }
    class GoogleOptions extends Options { ... }
    ...
    class Searcher
    {
    public Searcher(Options opt, ...) { ... }
    ...
    }
    ...
    new Searcher(new GoogleOptions(...), ...);
    ...

    It's perhaps difficult to convey these ideas adequately in just a few lines.
    I would suggest that you look carefully at your various classes and see how
    responsibilities can be shared with an eye on minimising inheritance.

    I hope this helps [amd perhaps provides useful ideas :)].

    Anthony Borla
     
    Anthony Borla, Nov 19, 2003
    #2
    1. Advertisements

  3. Hi
    Thanks for the information.
    I'm actually launching an external browser because Java's inbuilt HTML
    support does not have thing like:
    * JavaScript support;
    * Flash suppport;
    * complex layout support;
    * and it overlays stuff over the document;
    And when some one clicks a link of the search page, what if this page uses
    new features of Java? (rhetoriacal)

    Thanks,
    B.F.





     
    Brenton Fletcher, Nov 19, 2003
    #3
  4. Sure :) ! I just wasn't sure [based on the information available in your
    post] whether you were aware of other option(s), so I took the liberty of
    suggesting one.

    The reason I was so presumptuous is that I've noticed [in a fair number of
    postings to this and similar NG's] the use of 'Runtime.exec' to launch
    Internet-specific utilities like browsers and even utilities like 'ping' or
    similar when, with a little more work, whether to locate or write suitable
    code [java.net, etc], would result in a much more efficient and robust Java
    application. Putting this another way, use of 'Runtime.exec' seems to be the
    first option of the newbie / near beginner, and may, in many instances, well
    remain the *only* option. I wanted to do my bit to ensure that it wasn't
    yours :) !

    Cheers,

    Anthony Borla
     
    Anthony Borla, Nov 20, 2003
    #4
  5. Hi,
    I feel a bit bad because I think I may have been a bit strong in my writing.
    Thank you for your responce.

    B.F.

     
    Brenton Fletcher, Nov 20, 2003
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.