问题 单项选择题

某企业欲开发一款家用电器遥控系统,让用户只需使用一个遥控器即可控制某些家用电器的开与关。由于遥控系统需要支持形式多样的电器,因此,该系统的设计要求具有较高的扩展性。现假设需要控制客厅电视和卧室电灯,对该遥控系统进行设计所得UML类图如图2-2所示。图2-2类图所采用的设计模式是______,该模式的设计意图是______。应用该设计模式能够有效地让______之间的耦合性降至最低。


A.类LightCommand和类Light
B.类TVCommand和类TV
C.类RemoteController、类LightCommand和类TVCommand
D.类RemoteController、类Light和类TV

答案

参考答案:D

解析: 图2—2所示的UML类图所描绘的设计模式是Command(命令)模式。该模式的设计意图就是“将一个请求封装为一个对象,从而使用户可用不同的请求对客户进行参数化,对请求排队或记录请求日志,以及支持可撤销的操作”。其中一种应用场合就是抽象出待执行的动作以参数化某种对象,可用过程语言中的回调(Callback)函数表达这种参数化机制。Command模式是回调机制的一个面向对象的替代品。本试题中,设计该家用电器遥控系统时,为了保证遥控器和家用电器之间的独立性,定义了Command类,当用户按下遥控器上的按钮时,触发Command上的On或者Off方法,因此,一对按钮分别对应一个Command对象。题目中的LightCommand及TVCommand分别为Command的子类,该子类用于控制实际的Light及TV对象,将On与Off方法委托给Light及TV实现。本题中应用命令模式的目的是,使类RemoteController(遥控器)、类Light及类TV之间的耦合性降至最低。
Strategy(策略)模式的设计意图是,使得算法可独立于使用它的客户而变化。
Adapter(适配器)模式是一种类对象结构型模式。通过将一个类的接口转换成客户希望的另外一个接口。Adapter模式使原本由于接口不兼容而不能一起工作的那些类可以一起工作。
Observer(观察者)模式的设计意图是“定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新”。

完形填空
完形填空。
     Once upon a time, a man punished his 5-year-old daughter for   1    up the family's only roll of 
expensive gold wrapping paper. Money was tight and he became even more   2   when on Christmas 
Eve, he saw that the child had pasted (粘贴) the gold paper to     3     a box to put under the Christmas
 tree.   
       4    , the next morning the little girl, filled with    5   , brought the gift box to her father and said,
"This is for you, Daddy!" Hearing this, the father was   6    by his earlier conversation. But when he 
opened it, he found it was   7   and again his anger expanded, "Don't you know, young lady," he 
said    8   ,"when you give someone a present, there is supposed to be something inside the package!"
     The little girl looked up at him   9    tears rolling from her eyes and said: "Daddy, it's not empty. I 
blew kisses into it  10   it was all full."
     The father was deeply moved. He  11  on his knees and put his arms around his precious little girl. 
He begged her to  12   him for his unnecessary anger.
     An accident   13    the life of the child only a short time later and   14   is told that the father kept
 that little gold box by his bed for all the years of his life. And  15   he was discouraged or faced 
difficult problems he  16    open the box, take out an imaginary kiss, and   17   the love of this
 beautiful child who had put it there.
     In a very real   18   , each of us as human beings has been given an unseen golden box  19   with 
unconditional love and kisses from our children, family, friends and God.
     There is no more precious  20   anyone could hold.
( )1. A. breaking  
( )2. A. upset      
( )3. A. paint      
( )4. A. In addition
( )5. A. fear      
( )6. A. bothered  
( )7. A. empty      
( )8. A. politely  
( )9. A. in      
( )10. A. unless    
( )11. A. lay      
( )12. A. punish    
( )13. A. took      
( )14. A. this      
( )15. A. no matter
( )16. A. could    
( )17. A. imagine  
( )18. A. sense    
( )19. A. put      
( )20. A. present  
B. giving    
B. thankful  
B. draw      
B. However  
B. desire    
B. apologized
B. dirty    
B. angrily  
B. down      
B. until    
B. fell      
B. blame    
B. caused    
B. it        
B. even if  
B. should    
B. remember  
B. means    
B. filled    
B. feelings  
C. holding    
C. interrupted
C. decorate    
C. Worse still
C. excitement  
C. embarrassed
C. overfilled  
C. thoughtfully
C. with        
C. so that    
C. rose        
C. forgive    
C. survived    
C. she        
C. wherever    
C. would      
C. make        
C. method      
C. covered    
C. possession  
D. using      
D. terrified  
D. brush      
D. Moreover  
D. doubt      
D. annoyed    
D. expensive  
D. happily    
D. for        
D. in case    
D. went      
D. beat      
D. saved      
D. he        
D. whenever  
D. might      
D. find      
D. touch      
D. carried    
D. relation  
单项选择题