Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Simple Problem for 2nd year Comp Sci Class

Thread view: 
traviswinter@gmail.com - 19 Oct 2006 00:46 GMT
Hello everyone, looking at some of the other threads on the group this
should be cake :)

I'm doing an assignment (programming in Java) which implements a Heap
based Priority Queue.  Basically just trying to get it up and running.
The problem exists like this:

ArrayListCompleteBinaryTree implements the interface CompleteBinaryTree
which implements the interface Tree.  Tree has a replace method that
does not throw an exception.  The replace method in
ArrayListCompleteBinaryTree can throw an exception due to the way it's
implemented.  I would change the replace method in Tree but if I do so
another class, HeapPriorityQueue, which has an
ArrayListCompleteBinaryTree object in it's methods must also throw the
exception for the replace method.

Is there any way around this?  I'd figure that since
ArrayListCompleteBinaryTree already covers the exception, that
HeapPriorityQueue would already be covered.  Am I wrong?  Also, I
should mention that the code I'm using is direct out of our courses'
text (as we were told to use) but it is missing certain methods
(replace is actually given) and does not compile right out of the book.

This things due in a couple of days so I'd appreciate any help anyone
could give me.  Thanks!

Travis
Manish Pandit - 19 Oct 2006 01:56 GMT
If the interface does not declare exceptions, the implementation cannot
throw any checked exceptions. If it does, then the implementation can
declare the same checked exception or any of its subclasses. If your
implementation is causing the method to throw an exception, you have to
handle it within the method, or revisit the design as this indicates a
flaw in the design. Changing the interface signature just because an
implementation needs to throw an exception is not a good idea either.

One more thing - what do you mean by class XYZ already *covers* an
exception?

-cheers,
Manish
Oliver Wong - 19 Oct 2006 21:59 GMT
> ArrayListCompleteBinaryTree implements the interface CompleteBinaryTree
> which implements the interface Tree.  Tree has a replace method that
[quoted text clipped - 4 lines]
> ArrayListCompleteBinaryTree object in it's methods must also throw the
> exception for the replace method.
[...]
> Am I wrong?

   I think you're wrong. You can have Tree's replace declare itself as
throwing an exception, without having HeapPriorityQueue declare itself to
throw an exception.

   Alternatively, you could have HeapPriorityQueue go ahead and declare as
throwing an exception, but never actually throw the exception in the
implementation.

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.