java - How to override a indirectly invoked method -


i not sure how title question properly, try describe clear can : .

interface interfaceb {   void methodb(); }  class classb implements interfaceb {   void methodb() {     //...   } }  class classa {   interfaceb methoda() {     return new classb();   } } 

class myclass {   public static void main(string[] args) {     classa = new classa();     interfaceb b = a.methoda();     b.methodb();  // override guy   } } 

i want override methodb, without change classa , classb. appreciate ideas.

this can :

classa = new classa() {//extend class   interfaceb methoda() {//override methoda     return new classb() {//extend class b        void methodb() {//override methodb        //...        }     };   } }; 

you have overidden methodb without changing either class or class b. being said, don't need extend classa. create factory, pass classa dependency , pass parameter methoda telling concrete implementation of classb should used call methodb


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -