mercredi 23 octobre 2019

What's the design philosophy of netty class ChannelDuplexHandler?

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:

  1. Why extends ChannelInboundHandlerAdapter but not ChannelOutboundHandlerAdapter? only because ChannelOutboundHandler have fewer method to override?
  2. Why not use some smart ways to avoid this? (agency or warp patterns? I don't know if I pull the concept right)
  3. If the ChannelOutboundHandler add some new interface method, you have no choice but only to write the same code twice in ChannelOutboundHandlerAdapter and ChannelDuplexHandler? (or somewhere else maybe)

Aucun commentaire:

Enregistrer un commentaire