好文借鉴 引用对容器中元素的访问涉及到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 ...
2007-10-23

[置顶] Design Patterns and OOP

关键字: pattern
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 ...
CherryRemind
搜索本博客
我的相册
1c55394d-5f90-3900-a92d-bd2019c9fa82-thumb
Collection_Performance_Compare.JPG
共 1 张
最近加入圈子
存档
最新评论