Calling child constructor interlaced in parent constructor in java -


i have lots of children base class , plan adding lot more. i'm lazy. child creator sets basic things needed super constructor , vice versa. simple solution problem following:

parent {    public parent(){/*some code*/}    public void finalsetup(){/*code dependent on fact child constructor has run*/} } child{     public child(){/*some code;*/ super.finalsetup();} } 

how ever, calling super.finalsetup() on every child quite hassle, , if forget on 1 it'll break. that's no good. question simple: there way set form parent. far google skills go haven't been able find one. guys know don't.

thanks

this should want, mentioned, can not best idea. don't need explicitly call parent constructor in subclass if have no-argument constructor in superclass.

abstract class parent {     parent() {         /*some code*/         childinit();         finalsetup();     }     void finalsetup() {/*code dependent on fact child constructor has run*/}     abstract void childinit(); }  class child extends parent {     @override     void childinit() {         /* code put in child's constructor */     } } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -