码迷,mamicode.com
首页 > 其他好文 > 详细

存根类(stub) 是什么意思?有什么作用?(转)

时间:2014-07-23 16:57:21      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   

 存根类是一个类,它实现了一个接口,但是实现后的每个方法都是空的。 

 它的作用是:如果一个接口有很多方法,如果要实现这个接口,就要实现所有的方法。但是一个类从业务来说,可能只需要其中一两个方法。
 
如果直接去实现这个接口,除了实现所需的方法,还要实现其他所有的无关方法。而如果通过继承存根类就实现接口,就免去了这种麻烦
 
这个在omco2.6版本中用户登录的session中的接口就有体现。
 
 1 package com.utstar.omco.jnti.inc;  
 2    
 3    
 4 public interface ITBusStub extends IEngineHandle  
 5 {  
 6       ITAclInterface getAclInterface();  
 7       void setName(String name);  
 8       String getUUID();  
 9       int generateSID();  
10       int getSessionCount();  
11       ITServerSession getSession(int sid);  
12       ITServerSession[] getAllSession();  
13       int delSession(int sid, ITableRegChange ic);  
14       int _onRecvResult(Msg.MsgInfo msg);  
15       Msg.MsgInfo _onNeedExec();  
16       int _onRecvFromSession(ITServerSession s, Msg.MsgInfo msg);  
17       int _onRegister(Msg.ReguestRegister reg, ITableRegChange ic);  
18       void _onUpdateRegInfo(String src, ITableRegChange ic);  
19       int _onAddSession(ITServerSession s);  
20 }  
上面的类ITBusStub,就是一个stub类,它的作用主要是用于继承一个接口类,然后它的实现类只需要通过实现它这个接口就可以,
实现需要调用的方法。BusStub是它的实现类。
 1 public class BusStub extends AbsEngineHandle implements ITBusStub,IMonitor  
 2 {  
 3     public static interface MsgPriorityStrategy  
 4     {  
 5         public int onRecvResultPriority(Msg.MsgInfo msg);  
 6         public int onRecvFromSessionPriority(ITServerSession s,         Msg.MsgInfo msg);  
 7     }  
 8        
 9     public static class ResultPriorMsgPriorityStrategy implements MsgPriorityStrategy  
10     {  
11         public int onRecvResultPriority(Msg.MsgInfo msg)  
12         {  
13             return DefaultEngine.PRIO_HIGH;  
14         }  
15    
16         public int onRecvFromSessionPriority(ITServerSession s, Msg.MsgInfo msg)  
17         {  
18             return DefaultEngine.PRIO_DEFAULT;  
19         }  
20     }  
21        
22     AtomicInteger m_curSessionIdx = new AtomicInteger(1);  
23    
24     IMsgQueue<Msg.MsgInfo> m_cmdQue = new MsgQueue<Msg.MsgInfo>("cmd");  
25     IMsgQueue<Msg.MsgInfo> m_resultQue = new MsgQueue<Msg.MsgInfo>("result");  
26    
27     ConcurrentHashMap<Integer, ITServerSession> m_svc = new ConcurrentHashMap<Integer, ITServerSession>();  
28    
29     NotifyReg m_reg = new NotifyReg();  
30    
31     ITDispatch m_dispatch;  
32    
33     ITAclInterface m_acl = ITAclInterface.s_defaultAcl;  
34     String m_uuid = UUID.randomUUID().toString();  
35     String m_name;  
36        
37     MsgPriorityStrategy m_msgPriorityStrategy;  
38        
39     LongStatPrp sp_cmdnum = new LongStatPrp("recv cmd",0);  
40     LongStatPrp sp_resultnum = new LongStatPrp("send result",0);  
41     LongStatPrp sp_notifynum = new LongStatPrp("send notify",0);  
42        
43     private static final Log logger = LogFactory.getLog("comm");  
44        
45     public BusStub(String name)  
46     {  
47         this(name, null);  
48     }  
49    
50     public BusStub(String name, MsgPriorityStrategy msgPriorityStrategy)  
51     {  
52         m_name = name;  
53         m_msgPriorityStrategy = msgPriorityStrategy;  
54     }  
55        
56        
57     public String getName()  
58     {  
59         return m_name;  
60     }  
61     public void setName(String name)  
62     {  
63         m_name = name;  
64     }  
65    
66     public String getUUID()  
67     {  
68         return m_uuid;  
69     }  

 原文地址:http://www.2cto.com/kf/201310/249266.html

存根类(stub) 是什么意思?有什么作用?(转),布布扣,bubuko.com

存根类(stub) 是什么意思?有什么作用?(转)

标签:style   blog   http   color   os   io   

原文地址:http://www.cnblogs.com/heart-king/p/3863266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!