?
Solved

Calling method in sub-class' that over-writes super's

Posted on 2003-03-06
8
Medium Priority
?
183 Views
Last Modified: 2010-03-31
Apologies in advance for the cryptic title.

This should be simple, but for some reason I'm drawing a complete blank:

I have three classes:

* Provider
has 2 methods:
    - private getHttpURLConnection()
    - private getResponse()

The getResponse() makes a call to the getHttpURLConnection()

* SSHProvider (extends Provider)
has 1 method:
    - private getHttpURLConnection()

The method is to over-write the functionality of the getHttpURLConnection in the Provider class.

* Server
Gets an instance of SSHProvider and calls the getResponse() method on--which exists only in Provider.

The problem is that when the Server.getResponse() is called, it executes the Provider.getHttpURLConnection() (obviously).

What can I do to have getResponse() called in Server, on the SSHProvider object, make the call to the SSHProvider.getHttpURLConnection()?
0
Comment
Question by:aagha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 180 total points
ID: 8079683
Overwrite getResponse as well :-/
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8079687
Don't think there is any other way...could be wrong tho...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8079701
On first thoughts, it seems to me that you'll have to override getResponse too
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aagha
ID: 8079740
This is what I thought, and why I asked the question.

Rewrting getResponse means nearly duplicating, line-for-line (all except one), a large and ugly method.

Anyone think of another way?  Changing method visability, etc.?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8079754
The word is 'override' btw folks ;-)

Didn't see yours before i posted Tim.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8079770
Try to atomise the function, then you can call one or more parts of it as superX() and invoke the overridden parts as well when necessary
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8079965
:-)
0
 

Author Comment

by:aagha
ID: 8080333
:-)
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question