Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Restriction in interface

Reply
Thread Tools

Restriction in interface

 
 
Zhao
Guest
Posts: n/a
 
      10-24-2003
"...The Set interface extends Collection and contains no methods other
than those inherited from Collection. It adds the restriction that
duplicate elements are prohibited..."

How can Set, an interface, enforce the "no duplicate elements" without
any implementation?

My guess is that there is someting in the Collection framework carry
out this
enforcement.

Anyone konws?

thanks
 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      10-24-2003
Zhao wrote:

> "...The Set interface extends Collection and contains no methods other
> than those inherited from Collection. It adds the restriction that
> duplicate elements are prohibited..."
>
> How can Set, an interface, enforce the "no duplicate elements" without
> any implementation?
>
> My guess is that there is someting in the Collection framework carry
> out this
> enforcement.
>
> Anyone konws?
>


No, the implementations of Set are supposed to take care of this requirement.
HashSet for example is backed by a HashMap that is used to enforce the "only
unique elements" rule.

--
Regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      10-24-2003
Zhao wrote:

> "...The Set interface extends Collection and contains no methods other
> than those inherited from Collection. It adds the restriction that
> duplicate elements are prohibited..."
>
> How can Set, an interface, enforce the "no duplicate elements" without
> any implementation?


It cannot. An interface and its documentation specify a contract to
which implementations are expected to conform. The compiler and VM can
ensure that method signatures match, but it is up to individual classes
to implement behavior consistently with the demands of the contract.

This is really no different from subclassing an existing class. The
class documentation should define method contracts that specify what the
methods are supposed to do; subclasses should not violate these
contracts lest polymorphism be broken, but nothing enforces that. (By
the way, that is an excellent reason to seperate implementation details
from general contract details in method documentation.)

> My guess is that there is someting in the Collection framework carry
> out this
> enforcement.


The concrete classes in the Collections framework all abide by the
contracts set out in the top-level interfaces' documentation.


John Bollinger
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GLBP group restriction when using a sup2 and 6500 switch Tristan Cisco 0 03-08-2005 04:12 PM
Internet restriction =?Utf-8?B?R1RheWxvcg==?= Wireless Networking 1 08-07-2004 11:28 PM
file restriction - Forms authentication =?Utf-8?B?RWQ=?= ASP .Net 1 06-01-2004 07:45 PM
Re: Software Restriction Policies Bhargav Shukla MCSE 0 04-01-2004 06:08 PM
Re: Telnet restriction with access-list sPiDEr Cisco 0 06-23-2003 06:39 AM



Advertisments