design patterns - Java: Take anonymous class outside -


i have situation presented below:

class c1 {      public static void main(string[] args) {         object o = // new object of class         delegate(new c2() {             // c2 abstract class or interface             public void delegatelogic() {                 object my_o = o;  // refrences main's local variable                 // huge method body                 // object o local main required here               }         });     }      private void delegate(c2 c2) {         // method body     } } 

the body of delegatelogic() turning out big. code maintainability :

  1. i want create concrete class c2 , keep outside, while still having way use object o in main method.
  2. also, instance of c2 supposed serializable , unfortunately object o not serializable. so, not want create member object in c2 passing object o in constructor.

any ideas?

if want c2 able serialized, declare o transient. however, need accept fact o null if got serialized/deserialized unless manage serialize manually somehow.

public class x extends c2 {     private transient object o;      public x(object o) {         this.o = o;     }      public void delegatelogic() {         object my_o = o;  // refrences main's local variable         // huge method body         // object o local main required here       } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -