pu blic void op erati o n () {
// i m p l e mentation
}
}
pu blic class Co m p onentB imple m e n ts Co mpone n t {
pu blic void op erati o n () {
// i m p l e mentation
}
}
pu blic class De c orato r impl e m e nts Compon e n t {
pr i vate Com p o nent compon e n t ;
pr i vate Deco r a t ion de corati o n ;
pro t e cted D e c orato r ( De c o r ation deco rat ion , Com p o nent compo n e n t ) {
this . co mponen t = comp o n ent ;
this . de c oratio n = decora t i o n ;
}
pu blic void op erati o n () {
com p o nent . o p e ratio n ();
dec o r ator . a d d e d B e h avior ();
}
}
pu blic enum De c oratio n {
DEC O R A T IONA {
pu blic void ad d e d B e havior () {
// i m p l e mentation
}
},
DEC O R A T IONB {
pu blic void ad d e d B e havior () {
// i m p l e mentation
}
};
pu blic ab s t ract void ad d e d B e h a v ior ();
}
pu blic st atic voi d m ain ( Str i ng [] ar gs ) {
Com p o nent comp = new D e c o rator ( De c o r ation . D ECO RATI ONB ,
new Decor a t o r ( Decorat i o n . DECO RAT IONB ,
new Decor a t o r ( Decorat i o n . DECO RAT IONA ,
new Compone n t A ()))) ;