Results 1 to 3 of 3
  1. #1
    BobswYourUcle is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default Interface questoin

    Hello,

    I am trying to figure out when to and not to use an interface. I have a class that implements my interface and the classes that call that use that interface are in different projects.
    Now I want to create a new method within the class that implements the interface, however this time the method that will call it is within the same project and futhermore is in a helper class.

    Is this clear enough for someone to help me decide if I should add the new method into the interface or not?

    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    I want to create a new method within the class that implements the interface,
    There is no restriction on what methods you can add to a class that implements an interface. If the methods don't conflict with those in the interface there should be no problem.

    should add the new method into the interface
    That would depend on your usage and definition for what the interface means.
    It would require you to change all the other classes that implement the interface.

  3. #3
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    Like Norm said, it's your interpretation of how the design should be. There is no "must be" involved. My impression is that your "project with Interface" offers some services to the outer world, the interface is how the outer world should see this project and how it should communicate with the project via calls to this interface, and not bypass it (at least for this functionality). This interface should not be polluted with methods for project-internal use. You can compare it with private class-methods, but now on the level of projects: the same concept, but not enforced. Bottom line: you could (like making private methods public), but probably you shouldn't.
    It would require you to change all the other classes that implement the interface.
    This is true, but probably not a big issue because the interface defines the services your project offers: one implementation is enough. It is different when the other classes are the serviceproviders that have to comply to your interface, like plugins or different implementations of an algorithm. Then you might need adapters or adaptations to fit them in.
    No bug ever had to calculate its fitnessfunction.

Similar Threads

  1. interface
    By makrandubale in forum New To Java
    Replies: 9
    Last Post: 01-02-2011, 03:13 PM
  2. How do I use an Interface for this?
    By aaronfsimons in forum New To Java
    Replies: 14
    Last Post: 06-22-2009, 02:19 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
  •