Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java How to design - Interface Usage?

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java How to design - Interface Usage?

    I have a class as shown below.

    This class has a method addFilter with 2 parameters (type String and type Command1 )
    public class Command1 {
    public StringBuffer addFilter(String query, Command1 dataBase) {

    //concrete implementation

    return query;

    }
    }

    I have another class Command2. Here I need a similar method. The only difference is in the type of parameters passed. (type String and type Command).

    public class Command2 {
    //TO DO:
    public StringBuffer addFilter(String query, Command2 cmd) {

    //concrete implementation

    return query;

    }
    }

    I have started by using Interface
    public interface Helper {

    public StringBuffer addFilter(String query, XXXXX parameter2);

    }

    I would like the classes Command1 and Command2 to implement the interface Helper and override it these two public classes.
    However my problem is in dealing with the 2nd parameter. Am I right in my approach? Can anybody tell me how do I handle this issue?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java How to design - Interface Usage?

    What issue are you talking about? I'm really not sure what you're asking here.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java How to design - Interface Usage?

    public class Command1 implements Helper{

    //I need to pass the 2nd paramter as type Command1
    @Override
    public StringBuffer addFilter(String query, Command1 dataBase) {

    //concrete implementation

    return query;

    }
    }

    public class Command2 {
    //TO DO:
    //I need to pass the 2nd paramter as type Command2
    @Override
    public StringBuffer addFilter(String query, Command2 cmd) {

    //concrete implementation

    return query;

    }
    }

    public interface Helper {

    //What should the type of XXXXX be??
    public StringBuffer addFilter(String query, XXXXX parameter2);

    }

    --- Update ---

    public class Command1 implements Helper{

    //need to pass the 2nd paramter as type Command1 ??
    @Override
    public StringBuffer addFilter(String query, Command1 dataBase) {

    //concrete implementation

    return query;

    }
    }

    public class Command2 implements Helper{
    //TO DO:
    //need to pass the 2nd paramter as type Command2

    @Override
    public StringBuffer addFilter(String query, Command2 cmd) {

    //concrete implementation

    return query;

    }
    }

    public interface Helper {

    //What should the type of XXXXX be??
    public StringBuffer addFilter(String query, XXXXX parameter2);

    }

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java How to design - Interface Usage?

    When posting code, please use the highlight tags to preserve formatting.

    You tell us. What type should it be? What does that method do? What have you tried?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. wmi usage or PC info in java
    By roofninja in forum What's Wrong With My Code?
    Replies: 9
    Last Post: September 12th, 2012, 09:08 AM
  2. Problem with java program and CPU usage
    By Bahramudin in forum Java Theory & Questions
    Replies: 3
    Last Post: July 25th, 2012, 09:26 AM
  3. The problem with Java and CPU usage, need HELP
    By Bahramudin in forum Member Introductions
    Replies: 1
    Last Post: July 25th, 2012, 09:23 AM
  4. HashMap usage in Java
    By neo_2010 in forum Collections and Generics
    Replies: 2
    Last Post: September 18th, 2009, 02:12 AM
  5. Replies: 1
    Last Post: August 7th, 2008, 02:09 AM

Tags for this Thread