2013年12月7日

单态模式

摘要: Singleton模式主要作用是保证在面向对象编程语言设计编写的程序中,一个类Class只有一个实例存在。在很多操作中,比如建立目录 数据库连接都需要这样的单线程操作。还有, singleton能够被状态化; 这样,多个单态类在一起就可以作为一个状态仓库一样向外提供服务,比如,你要论坛中的帖子计数器,每次浏览一次需要计数,单态类能否保持住这个计数,并且能synchronize的安全自动加1,如果你要把这个数字永久保存到数据库,你可以在不修改单态接口的情况下方便的做到。另外方面,Singleton也能够被无状态化。提供工具性质的功能,Singleton模式就为我们提供了这样实现的可能。使用Sin 阅读全文

posted @ 2013-12-07 02:55 Step-BY-Step 阅读(229) 评论(0) 推荐(0) 编辑

Chp18: Hard

摘要: 18.1 Write a function that adds two numbers. You should not use + or any arithmetic operators.Solution: deal with 759 + 674.1. add 759 + 674, but forget to carry. get 3232. add 759 + 674, but only do the carrying, rather than the addition of each digit. get 11103. add the result of the first two ope 阅读全文

posted @ 2013-12-07 02:27 Step-BY-Step 阅读(210) 评论(0) 推荐(0) 编辑

导航