The Artima Developer Community
Sponsored Link

Java Answers Forum
Implements when extending implementation

4 replies on 1 page. Most recent reply: Jun 9, 2003 1:50 AM by John Channing

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Walter Rumsby

Posts: 4
Nickname: wrumsby
Registered: Jun, 2003

Implements when extending implementation Posted: Jun 6, 2003 9:13 PM
Reply to this message Reply
Advertisement
Hi,

I have a stylistic question.

If I have the following interfaces and classes:


public interface Transaction

public class TransactionImpl implements Transaction

public interface Enquiry

public class AccountEnquiry extends TransactionImpl implements Enquiry, Transaction



I know that I don't need to add "implements Transaction" when defining AccountEnquiry, but it seems somewhat clearer.

Your thoughts on this if you care to comment.


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Implements when extending implementation Posted: Jun 7, 2003 8:15 AM
Reply to this message Reply
The line:
public class AccountEnquiry extends TransactionImpl implements Enquiry, Transaction

does not need to have the "implements Transaction" unless you intend to add a different version of the methods required to implement Transaction

John Channing

Posts: 17
Nickname: drc
Registered: Jun, 2003

Re: Implements when extending implementation Posted: Jun 8, 2003 1:27 PM
Reply to this message Reply
does not need to have the "implements Transaction" unless you intend to add a different version of the methods required to implement Transaction

Why does it need to state that it "implements Transaction" in that case? How does the classes behaviour change? What do you gain?
John

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Implements when extending implementation Posted: Jun 8, 2003 5:38 PM
Reply to this message Reply
If the class AccountEnquiry is not going to override the methods required to implement its own version of the Transaction interface, then you should not add "implements Transaction" to the class declaration statement.

John Channing

Posts: 17
Nickname: drc
Registered: Jun, 2003

Re: Implements when extending implementation Posted: Jun 9, 2003 1:50 AM
Reply to this message Reply
If the class AccountEnquiry is not going to override the methods required to implement its own version of the Transaction interface, then you should not add "implements Transaction" to the class declaration statement.

I would concede this is an area of style rather than substance, however here is my opinion on the subject.

Even if it does override the implementation given in the super class there is no need to restate that it implements Transaction, because that is already the case. Stating that the class implements Transaction neither changes its behaviour nor does it add any real clarity or value to a programmer who understands inheritance. You don't need to do it, so don't bother!
John

Flat View: This topic has 4 replies on 1 page
Topic: migrating to linux Previous Topic   Next Topic Topic: Error: java.security.AccessControlException: access denied

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use