• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Uses of Interfaces

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends

The fallowing are the uses of interfaces in java, can somebody explain me these two thigs

1) Capturing similarities between unrelated classes without forcing a class relationship

2) Revealing an object's programming interface without revealing its class
thanx in advance

regards
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by johnson david:
Hi friends

The fallowing are the uses of interfaces in java, can somebody explain me these two thigs

1) Capturing similarities between unrelated classes without forcing a class relationship

2) Revealing an object's programming interface without revealing its class
thanx in advance

regards




For part 1, when a class definition implements an interface, there is an "is a" relationship.

This means that two classes that are completely different can have an "is a" relationship with the same interface, and can be sent as parameters to methods that accept the interface type.

An example would be Comparable. You can have many diverse classes that implement the Comparable interface. But if you create a sort method whose parameter type is Comparable, then you can send two different objects created from classes that don't really have anything else in common.

For part 2, an interface only contains inteface constants and abstract methods. This means that you see the methods that must be contained in the class if it implements the interface simply by looking at the abstract methods in the interface definition.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For more detail, you may want to read the Interfaces chapter from Bruce Eckel's Thinking in Java.
 
Johnson David
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Keith


regards

johnson
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic