存根类(stub) 是什么意思?有什么作用?
2013-10-11 16:17
337 查看
存根类是一个类,它实现了一个接口,但是实现后的每个方法都是空的。
它的作用是:如果一个接口有很多方法,如果要实现这个接口,就要实现所有的方法。但是一个类从业务来说,可能只需要其中一两个方法。如果直接去实现这个接口,除了实现所需的方法,还要实现其他所有的无关方法。而如果通过继承存根类就实现接口,就免去了这种麻烦
这个在omco2.6版本中用户登录的session中的接口就有体现。
上面的类ITBusStub,就是一个stub类,它的作用主要是用于继承一个接口类,然后它的实现类只需要通过实现它这个接口就可以,
实现需要调用的方法。BusStub是它的实现类。
它的作用是:如果一个接口有很多方法,如果要实现这个接口,就要实现所有的方法。但是一个类从业务来说,可能只需要其中一两个方法。如果直接去实现这个接口,除了实现所需的方法,还要实现其他所有的无关方法。而如果通过继承存根类就实现接口,就免去了这种麻烦
这个在omco2.6版本中用户登录的session中的接口就有体现。
package com.utstar.omco.jnti.inc; public interface ITBusStub extends IEngineHandle { ITAclInterface getAclInterface(); void setName(String name); String getUUID(); int generateSID(); int getSessionCount(); ITServerSession getSession(int sid); ITServerSession[] getAllSession(); int delSession(int sid, ITableRegChange ic); int _onRecvResult(Msg.MsgInfo msg); Msg.MsgInfo _onNeedExec(); int _onRecvFromSession(ITServerSession s, Msg.MsgInfo msg); int _onRegister(Msg.ReguestRegister reg, ITableRegChange ic); void _onUpdateRegInfo(String src, ITableRegChange ic); int _onAddSession(ITServerSession s); }
上面的类ITBusStub,就是一个stub类,它的作用主要是用于继承一个接口类,然后它的实现类只需要通过实现它这个接口就可以,
实现需要调用的方法。BusStub是它的实现类。
public class BusStub extends AbsEngineHandle implements ITBusStub,IMonitor { public static interface MsgPriorityStrategy { public int onRecvResultPriority(Msg.MsgInfo msg); public int onRecvFromSessionPriority(ITServerSession s, Msg.MsgInfo msg); } public static class ResultPriorMsgPriorityStrategy implements MsgPriorityStrategy { public int onRecvResultPriority(Msg.MsgInfo msg) { return DefaultEngine.PRIO_HIGH; } public int onRecvFromSessionPriority(ITServerSession s, Msg.MsgInfo msg) { return DefaultEngine.PRIO_DEFAULT; } } AtomicInteger m_curSessionIdx = new AtomicInteger(1); IMsgQueue<Msg.MsgInfo> m_cmdQue = new MsgQueue<Msg.MsgInfo>("cmd"); IMsgQueue<Msg.MsgInfo> m_resultQue = new MsgQueue<Msg.MsgInfo>("result"); ConcurrentHashMap<Integer, ITServerSession> m_svc = new ConcurrentHashMap<Integer, ITServerSession>(); NotifyReg m_reg = new NotifyReg(); ITDispatch m_dispatch; ITAclInterface m_acl = ITAclInterface.s_defaultAcl; String m_uuid = UUID.randomUUID().toString(); String m_name; MsgPriorityStrategy m_msgPriorityStrategy; LongStatPrp sp_cmdnum = new LongStatPrp("recv cmd",0); LongStatPrp sp_resultnum = new LongStatPrp("send result",0); LongStatPrp sp_notifynum = new LongStatPrp("send notify",0); private static final Log logger = LogFactory.getLog("comm"); public BusStub(String name) { this(name, null); } public BusStub(String name, MsgPriorityStrategy msgPriorityStrategy) { m_name = name; m_msgPriorityStrategy = msgPriorityStrategy; } public String getName() { return m_name; } public void setName(String name) { m_name = name; } public String getUUID() { return m_uuid; }
相关文章推荐
- 视频转换中的码率是什么意思?它的大小有什么作用?
- #define WINVER 0x0500有什么意思?起什么作用?
- nofollow是什么意思?nofollow标签的写法和作用
- sfc /scannow是什么意思,有什么作用?(转载)
- nofollow是什么意思?nofollow标签的写法和作用
- C++ 中stdafx.h中文意思,并且在C++中起到的作用是什么?
- JQuery中$(document)是什么意思有什么作用
- sql中左连接是什么意思啊,有什么作用啊?能否给个例子,谢谢大家
- 1. 请问PHP里的ECHO是什么意思 ?请问PHP里的ECHO是什么意思???有什么作用???又应该怎么使用???
- 上行带宽和下行带宽是什么意思?各有什么作用?
- isKindOfClass是什么意思?有什么作用 (转)
- 什么是存根类 Stub
- C++中"std::"是什么意思?起什么作用?namespace?iostream和iostream.h的区别
- cout函数在C++中是什么意思和和作用
- 引用css和js链接地址中带的问号是什么意思?有什么作用?
- Oracle 中的SID是什么意思?有什么作用?
- spring中<tx:advice></tx:advice>是什么意思?作用是什么?谁能简单说下
- U盘量产是什么意思?有什么作用?
- AddSubView代码什么意思啊?AddSubView函数有什么作用?
- hibernate的配置文件*hbm.xml的class标签的 schema 是什么意思有什么作用?