Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overriding method...

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
Hello,

I need to override a specific method which is subclassed pretty far down.

I am calling this function...

Code:
[blue]
IPlan myPlan = PlanFactory.getPlan("foobar");
    return Plan.getInstance( aPlanId );
        plan = new Plan(planId);
            singleton = new PlanDataCache();
                PlanDataCache dataCache = PlanDataCache.getInstance();
               			  planDataCacheData.setPlanData( mPlanDataCacheData.loadBackendPlanData());


 	[b]LD11Data loadBackendPlanData() throws Exception[/b]
        {
             [green]//Do some stuff...[/green]
        }

[/blue]

I can only override this function in the file where the original call is made to IPlan myPlan = PlanFactory.getPlan("foobar").

Can I do it?

Can someone provide me any examples?
I figured it would look something along the lines of...
Code:
[blue]
IPlan myPlan = PlanFactory.getPlan("foobar")
{
  [b]LD11Data loadBackendPlanData() throws Exception[/b]
     {
         [green]//Do some other stuff...[/green]

     }

};
[/blue]

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
I'm a little bit confused, because the first block of code you posted returns unquivocably on the 2nd line ...

With regards to whether or not you can override the getPlan() method - then I would say you couldn't. The method is a static method on the "PlanFactory" class - so without changing the actual caller's code, then no.

--------------------------------------------------
Free Database Connection Pooling Software
 
Hi

I don't understand your problem. Can you post a very simple code, with easy variable name ?

One thing : you override only methods of Interfaces that your class implements, so superclasses and not subclasses.. right ?
 
>>>> I don't understand your problem. Can you post a very simple code, with easy variable name ?

Eh ?

>>>> One thing : you override only methods of Interfaces that your class implements, so superclasses and not subclasses.. right ?

The call "PlanFactory.getPlan("foobar")" is a static method call on a concrete object - no interfaces here - unless you have the code, I don't see a way you can alter than EXACT call ...

--------------------------------------------------
Free Database Connection Pooling Software
 
I apologize for the way the code is written.

The first line of code calls the second line of code. Somewhere in the 2nd function the third line of code is called and so on... The code is not in order they are just the lines that call each different hierarchical class which eventually lead to the function I need to override.

Unfortunately I don't have the code where I am writing this reponse but if you can imagine...

Code:
[blue]IPlan myPlan = PlanFactory.getPlan("foobar");[/blue]

directly calls

[blue]return Plan.getInstance( aPlanId );[/blue]

which then calls

[blue]plan = new Plan(planId);[/blue]

...



And yeah, I was hoping since PlanFactory.getPlan eventually ends up calling the functon through a chain of other functions I hoped I could override it, and yes I mean superclasses.


Hope that helps (or confuses you more),
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Unfortunately, my response earlier still stands (unless I am serisouly missing a main aspect of Java programming [ anyone ?]) :

The call "PlanFactory.getPlan("foobar")" is a static method call on a concrete object - no interfaces here - unless you have the code, I don't see a way you can alter than EXACT call ...

--------------------------------------------------
Free Database Connection Pooling Software
 
I still don't really understand what your piece of code mean, but whatever.

But if you want to override you getPlan() method, create an Interface class with this method as parameter (without body of).

After, all the classes that have to override getPlan() should implements this Interface.

Maybe it's not what you were waiting for..
Good luck
 
I'm not sure you really mean "override". What you want to do is to modify getPlan method in FactoryPlan class.

That cannot be done without changing the FactoryPlan code.

Cheers,

Dian
 
... unless you use an Aspect Orientation approach like AspectJ. You can modify the code's behaviour using point-cuts without changing the code itself.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
You know me sedj ... I like to muddy the water [smile].

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Interesting,

Thanks guys!

-Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top