好文借鉴
引用对容器中元素的访问涉及到3个方面。
1.容器的类型
2.检索容器内元素的方法
3.对元素的操作
比如说我们有一个表示书店的book_store类。里面保存了各种各样的book类的实例。
book类有name和type两种属性。表示书的名字和类别。
因此book_store类内部会用一个容器来保存book的实例。比如list。
class book
{
public:
string name;
string type;
};
class book_store
{
private:
list<book> m_books;
};
我们现在有这样一个简单的应用,那就是输出所有的 ...
好文借鉴
引用
1. Flyweight是减少内存的使用量的一种模式,间接的可能会提高性能。两者没有必然联系。
2. Flyweight和Object pool完全不同。FlyWeight内部用到的共享机制在实现上和object cache有点像,但是有本质上的区别。不要把两者混为一谈。请仔细读一下GoF的原著。
3. Flyweight未必会减少实例的创建次数。反而可能会增加实例的创建次数。(尤其对于非JAVA语言)
4. Flyweight内部的共享机制和object pool的区别。
4.1 原理不同
object pool的原理是复用(一个对象被反复使用,但同时只有一个“人” ...
重构:
在不改变的前提下,提高代码的可理解性,降低其修改成本
The rule of three
添加功能时一并重构
修补错误时一并重构
复审代码时一并重构
composing method
a. Extract method. divide a method into two or more method.
提炼方法, 把能分开,重用的部分单独做一个方法。
b. Inline method. conclude two or method into one method.
和Extract method相反, 概括多个方法成一个, 简化代码.
c. Inline temp ...
Design Patterns
A design pattern is a recurring solution to a standard problem.
The most well-known design patterns (in total 23) were documented by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides also called The Gang of ...
- 浏览: 6041 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
我的相册
Collection_Performance_Compare.JPG
共 1 张
共 1 张
最新评论
-
Date with timezone conve ...
Java的SimpleDateFormat可以设置TimeZone,这样得到的日 ...
-- by usherlight






评论排行榜