• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Programming to an interface

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For OCA Java SE 7, Mala Gupta does not mention "Programming to an Interface" in her book.
Edward Finegan mentions the following points on page 312 of his book.

Programming to an interface is the concept that

1. Code should interact based on a defined set of functionality instead of an explicitly defined object type.
2. It is better for the public interfaces of objects to use data types that are defined as interfaces as opposed to a particular class when possible.
3. When an object is implementing an interface, it is declaring that it has a certain set of functionalities.
4. Many different classes can implement the same interface and provide its functionality.
5. When a method uses an interface as its argument type, it allows any object, regardless of its type, to be used as long as it implements the interface.
6. Programming to an interface is also known as "design by contract."
7. Programming to an interface allows the developer to specify the capabilities or behaviors that are expected, instead of strictly defining an expected object type.

Example of Programming to an interface:


Question: Besides the points listed for "Programming to an Interface",
what additional items should one be aware of with respect to this topic?

Any additional examples of "Programming to an Interface" would be appreciated?
 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Programming to an interface, not an implementation is a good design practice!

Here you'll find some more info about this topic.
 
Thomas Hauck
Ranch Hand
Posts: 106
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the techniques used to program to an interface
is to write a method that contains a parameter of type interface.

Question:
If a method contains a parameter that is of an interface type,
is this technique automatically considered "programming to an interface?"


 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Hauck wrote:If a method contains a parameter that is of an interface type, is this technique automatically considered "programming to an interface?"


Of course!
reply
    Bookmark Topic Watch Topic
  • New Topic