This is what ChannelDuplexHandler javadoc said:
ChannelHandler implementation which represents a combination out of a ChannelInboundHandler and the ChannelOutboundHandler.
and the class definition as below:
public class ChannelDuplexHandler extends ChannelInboundHandlerAdapter implements ChannelOutboundHandler
ChannelDuplexHandler
extends ChannelInboundHandlerAdapter
to use all of its template methods, while Java not supports multi inheritance, so (maybe in a compromise way?) ChannelDuplexHandler
implement ChannelOutboundHandler
and overrides every methods which are exactly the same with ChannelOutboundHandlerAdapter
implementation.
Is this redundant work fragile? As someday once decide to change the ChannelOutboundHandler
template behavior, I have to change the ChannelDuplexHandler
implementation mirroring?
So my questions are:
- Why extends
ChannelInboundHandlerAdapter
but notChannelOutboundHandlerAdapter
? only becauseChannelOutboundHandler
have fewer method to override? - Why not use some smart ways to avoid this? (agency or warp patterns? I don't know if I pull the concept right)
- If the
ChannelOutboundHandler
add some new interface method, you have no choice but only to write the same code twice inChannelOutboundHandlerAdapter
andChannelDuplexHandler
? (or somewhere else maybe)
Aucun commentaire:
Enregistrer un commentaire