1,所谓laying,就是以一个class为本,建立另外一个class.
外层class含有内层class作为其数据成员.
例如:
class Address { ... }; // where someone lives
class PhoneNumber { ... };
class Person
{
public:
...
private:
string name; // layered object
Address address; // ditto
PhoneNumber voiceNumber; // ditto
PhoneNumber faxNumber; // ditto
};
对比public继承"是一种",layering意味着"有一个"或"根据某物实现".
2,应用,利用List实现Set.
template<class T>
class Set
{
public:
bool member(const T& item) const;
void insert(const T& item);
void remove(const T& item);
private:
list<T> rep;
};
template<class T>
bool Set<T>::member(const T& item) const
{
return find(rep.begin(), rep.end(), item) != rep.end();
}
template<class T>
void Set<T>::insert(const T& item) const
{
if(!member(item))
rep.push_back(item);
}
template<class T>
void Set<T>::remove(const T& item) const
{
list<T>::iterator ite = find(rep.begin(), rep.end(), item);
if (ite != rep.end())
rep.erase(ite);
}
注:这里List和Set的关系不是"isa",Set不允许元素重复,而是"根据某物实现"的关系.
3,需要注意的是:当你使用laying技术来模塑两个class之间的关系时,你便在那些class之间产生了一个编译依存关系.
分享到:
相关推荐
UVM分层验证环境架构
layering-cache简介layering-cache是一个支持分布式环境的多级缓存框架,使用方式和spring-cache类似。使用Caffeine作为一级本地缓存,使用redis作为二级集中式缓存。一级缓存和二级缓存的数据一致性是通过推和拉两...
layering-cache是一个支持分布式环境的多级缓存框架,使用方式和spring-cache类似。它使用Caffeine作为一级本地缓存,redis作为二级集中式缓存。一级缓存和二级缓存的数据一致性是通过推和拉两种模式相结合的方式来...
lecture-03-layering-naming-filesystem-design.pptx
While it is fairly easy to understand, you still need a quick guide to bring you up to speed before Vista's release, and that's where this book's simple, no nonsense approach comes in. <br>XAML in...
VoIPDemo is intended as a sample to show how to use the RTC API for Windows CE, but also as a working application for demonstration and use (taking note of the limitations described below). ...
Cross-Layering Optimization for Low Energy Consumption in Wireless Body Area Networks
How a counting semaphore is implemented How a multiple-reader, single-writer lock works Advantages of multiple LWPs for a given process 3. Hardware Memory Management How the MMU tables are used to ...
In inertial fusion energy (IFE) research, a number of technological issues have focused on the ability to inexpensively fabricate large quantities of free-standing targets (FSTs) by developing a ...
DICE 相关技术规范
Replit.com已经有一个经过编译的jar,可以用它快速绘制图形jar运行命令: kotlin -classpath main.jar MainKt "path to graph file" 示例: kotlin -classpath main.jar MainKt "examples/flow-from-lesson" ...
一个在Flex中显示HTML网页的控件,当然不仅仅只这个,官方网站: http://drumbeatinsight.com/htmlcomponent 控件供述: - Extends the Adobe’s™ UIComponent class (no need to relearn a new system) - ...
idle machines into hosts for numerous Docker services.Learn what it takes to build a true container infrastructure that is scalable, reliable, and resilient in the face of increased complexities from ...
this is somebody else’s problem or let us design the major functionalities first, then bring in a cryptographer to secure it! This treatment of security as an add-on feature typically led either to ...
I&A for Users and Groups in a Network Security Models within Models Network Node I&A Software Can Be a Network Entity Network Access Control Network Application Access Controls The Importance of...
需要 node.js 和一个节点包:$ npm install command 跑步 将 aco.js 作为脚本运行: $ node aco.js --help 某些命令并不完全按照宣传的方式运行。 黑客攻击 这是超级正在进行中的 hacktastic 实验代码。 很多事情不...
idle machines into hosts for numerous Docker services.Learn what it takes to build a true container infrastructure that is scalable, reliable, and resilient in the face of increased complexities from ...
给定一个图及其边的分层,返回一个插入了虚拟顶点的新图,这样任何边都不能跨越一个以上的层。 应用程序接口 addPhonies(layer:Layering, to:Edges, from:Edges[, i:Interface]) → Result Result { layering: ...
Javascript音板本练习的目的是创建和使用高阶函数来围绕播放音频提供不同的功能。 声音资源: 设置克隆此存储库,然后在google chrome中打开文件。 您可以从命令行open index.html ,或双击Finder中的文件。 您将...