聚合:类型之间的一种关系,就是一种类型内含有另一种类型的变量。

has-a:

 class Address
{ }; class PhoneNumber
{ }; class Person
{
public: private:
std::string name;
Address address;
PhoneNumber cellphone;
};

说明:Person中包含姓名、地址、手机号,是一种典型的has-a关系。

is-implemented-in-terms-of(根据一种类型实现另一种类型):

用链表List实现集合Set[具体如何实现请参考《算法精解:C语言描述 第7章》],但是我们知道List可以包含重复的元素,而set不能重复,因此set不是一个List,即通过public继承不能满足要求。当然也可以重新设计一个set,但是由于set中的大部分操作与List一样,本着软件重用的思想,set可以如下定义:

 template<typename T>
class Set
{
public:
bool member(const T& item) const;
void insert(const T& item);
void remove(const T& item);
std::size_t size() const; private:
std::list<T> rep;
};

总结:

has-a意味着一种类型是另一种类型的补充;is-implemented-in-terms-of意味着一种类型要靠另一种类型才能实现。

条款38:通过聚合设计has-a或者is-implemented-in-terms-of的更多相关文章

  1. 关于领域驱动设计(DDD)中聚合设计的一些思考

    关于DDD的理论知识总结,可参考这篇文章. DDD社区官网上一篇关于聚合设计的几个原则的简单讨论: 文章地址:http://dddcommunity.org/library/vernon_2011/, ...

  2. ElasticSearch 2 (38) - 信息聚合系列之结束与思考

    ElasticSearch 2 (38) - 信息聚合系列之结束与思考 摘要 版本 elasticsearch版本: elasticsearch-2.x 内容 本小节涵盖了许多基本理论以及很多深入的技 ...

  3. 任务38:JWT 设计解析及定制

    任务38:JWT 设计解析及定制 改造jwt token token的值不放在Authorize里面,而是放在header的token里面 asp.net core的源代码 在Security的下面 ...

  4. ddd 聚合根 之 聚合与不聚合 设计

    聚合 不聚合 订单和订单明细 论坛主贴与贴子回复 订单和收货地址(vo)  

  5. 条款38 通过复合塑膜出has-a或&quot;依据某物实现&quot;

    结论: 复合的意义和public继承全然不同. (public继承參考:条款32 确定你的public继承塑模出is-a关系) 在应用域,复合意味着has-a(有一个).在实现域,复合意味着is-im ...

  6. Effective C++ -----条款38:通过复合塑模出has-a或“根据某物实现出”

    复合(composition)的意义和public继承完全不同. 在应用域(application domain),复合意味has-a(有一个).在实现域(implementation domain) ...

  7. SSAS 聚合设计提升CUBE的查询性能(转载)

    Problem What exactly are SQL Server Analysis Services (SSAS) Aggregations and how exactly can I revi ...

  8. Effective C++:条款38:通过一个复杂的模具has-a要么“基于一些实现”

    (一) public继承是"is-a"关联,"has-a"或"依据某物实现出(is-implemented-in-terms-of)"的意思 ...

  9. 条款38:通过复合塑模has-a或“根据某物实现出”

    NOTE: 1.复合(composition)的意义和public继承完全不同. 2.在应用域(application domain),复合意味 has-a(有一个). 在实现域(implementa ...

随机推荐

  1. python常用内置函数

    Python所以内置函数如下: 下面列举一些常用的内置函数: chr()和ord() chr()将数字转换为对应的ascii码表字母 >>> r=chr(65) >>&g ...

  2. 理解Linux启动过程

    传统的Linux系统启动过程主要由著名的init进程(也被称为SysV init启动系统)处理,而基于init的启动系统被认为有效率不足的问题,systemd是Linux系统机器的另一种启动方式,宣称 ...

  3. Unity Js与C#脚本通信

    将.js文件放到Standard Assets目录下,否则无法编译通过 CS_test.cs : using UnityEngine; using System.Collections;   publ ...

  4. LESS 拓展选择器extend基础用法说明

    扩展选择器是less的伪类选择器,他会复制当前选择器,定义新的样式,而原来的不变 nav ul { &:extend(.inline); background: blue; } .inline ...

  5. Python之路【第六篇】:socket

    Python之路[第六篇]:socket   Socket socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字&quo ...

  6. Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed.

    地图定位 错误:使用CoreLocation获取地理位置信息,报错 Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be ...

  7. MySQL允许远程访问

    grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; flush privileges; ...

  8. atexit注册的函数是在main函数之后执行?

    跟atexit函数相识已久,man手册里对atexit的解释是这么一段: The atexit() function registers the given function to be called ...

  9. Permission Lists Assigned to a User

    SQL that I find useful in many occasions. It will return a list of permissions that are assigned to ...

  10. PHP-POSIX正则表达式函数

    1.ereg() 格式:ereg("条件",<原始字符串>) ereg()查找字符串,是严格区分大小写的 <?php $string="apples a ...