问题 问答题 简答题

单件实例是什么?

答案

参考答案:

Foundation和ApplicationKit框架中的一些类只允许创建单件对象,即这些类在当前进程中的唯一实例。举例来说,NSFileManager和NSWorkspace类在使用时都是基于进程进行单件对象的实例化。当向这些类请求实例的时候,它们会向您传递单一实例的一个引用,如果该实例还不存在,则首先进行实例的分配和初始化。单件对象充当控制中心的角色,负责指引或协调类的各种服务。如果类在概念上只有一个实例(比如NSWorkspacE.,就应该产生一个单件实例,而不是多个实例;如果将来某一天可能有多个实例,您可以使用单件实例机制,而不是工厂方法或函数。

完形填空

阅读短文,根据短文内容及首字母提示,在空白处填入一个适当的单词。

Years ago in Scotland, the Clark family had a dream. The couple worked and saved, making小题1: p     for their nine children and themselves to travel to the USA. It had taken years before they saved enough money and got everything小题2: r        for the trip.

The whole family was excited about their new life. However, seven days 小题3: b________       they left for the USA, the youngest son was bitten by a dog. The doctor treated the boy, 小题4: b____      because there was a possibility of rabies(狂犬病), they would be kept away from others for fourteen days.

The family’s dream could not come小题5: t   __   . They would not be able to make the trip to America as they had planned. Watching the ship leave---without the Clark family, the father was quite 小题6: a      with both his son and God for their bad luck.

Five days later, a piece of sad news小题7: s   __   throughout Scotland---the strong and powerful ship, Titanic, had gone down, taking小题8: h        of lives with it. The Clark family was to have been on that ship, but because the son was bitten by a dog, they were left 小题9: b_____        in Scotland.

When Mr Clark heard the news, he thanked his son for saving the family. He thanked the God for小题10: t       a sad thing into a good one.

Although we may not always understand, all things happen for a reason.

单项选择题