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 7 of 7

Thread: modularity and interfaces:

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default modularity and interfaces:

    I am studying OSGI and it seems that it always wants me to create a interface, then my code and put the whole thing in one package. In C++ this sort of thing in forced with the .h file besides the fact if you forgot to program a method it will still compile. Is it good programming practice to always create a interface? Before this I have just threw everything into one package and used inheritance.


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: modularity and interfaces:

    Having interfaces for your classes can be very useful. It allows you to switch implementations half-way through your project without affecting any other parts of your application. It also gives you the flexibility of choosing an implementation best suited for the current situation. If your interfaces are only ever implemented by one lonely class, then it might seem redundant. But most of the time its hard to foresee the future and maybe at some point in time another implementation will become useful and you will thank god that you had the foresight to create an interface.

    Its mostly personal preference and experience. I would advice you to use interfaces as often as possible because it encourages good coding practice and a clear documentation.

  3. The Following User Says Thank You to Cornix For This Useful Post:

    GregBrannon (August 18th, 2014)

  4. #3
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: modularity and interfaces:

    Thank you...

    Do you use OSGI?

    I have taken notice to Spring and it seems to have something for modularity already. I guess I am trying to wrap my head around this new concept. I understand it but all these frameworks can be overwhelming.

  5. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: modularity and interfaces:

    I have never worked with the OSGI model, but I thought your question was more about the idea behind it.

  6. #5
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: modularity and interfaces:

    It was/is, I was just wondering if you worked with it so I could pick your brain a little more.

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

    Thumbs up Re: modularity and interfaces:

    it is always preferable to use interface to increase the modularity of project follow lc-rp(loose coupling - runtime polymophism)

  8. #7
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: modularity and interfaces:

    I am adopting this way of programming. What about packages? Is there a rule of thumb or good practice with modularity when creating packages? For example, take interface car, and make it its own package, then I'll have a differnt package with the implementation Class Ford, and I have several cars. Should each car be in its own package and import package with the interface, or mash them all together?

    Am I on track on how this should work? Trying to develop good practices...

Similar Threads

  1. Interfaces
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 14
    Last Post: July 13th, 2018, 12:57 AM
  2. Interfaces...
    By eggpulusu in forum Java Theory & Questions
    Replies: 1
    Last Post: September 17th, 2013, 10:52 AM
  3. [SOLVED] What good are interfaces?
    By summit45 in forum Object Oriented Programming
    Replies: 2
    Last Post: August 18th, 2013, 09:39 PM
  4. Question Regarding Interfaces
    By davidrobin in forum Object Oriented Programming
    Replies: 1
    Last Post: April 18th, 2013, 04:10 PM
  5. Interfaces
    By leyland in forum Java Theory & Questions
    Replies: 4
    Last Post: April 5th, 2011, 08:51 PM