Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-06
8
Medium Priority
?
184 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
  • 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
Independent Software Vendors: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

564 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