
设计模式
懵圈丰
这个作者很懒,什么都没留下…
展开
-
nodejs 设计思想杂记 三 observer模式
观察者模式:一个对象,当其状态改变时能够通知一系列的观察者。EventEmitter看图说话使用方法:var EventEmitter = require('events').EventEmitter;var eeInstance = new EventEmitter();提供有几个接口:on(event, listener): 对event与linst原创 2016-07-06 12:55:38 · 1701 阅读 · 0 评论 -
nodejs 单例模式实现
function Logger(name) {if(!(this instanceof Logger)) {return new Logger(name);}this.name = name;};原创 2016-07-06 00:12:43 · 3788 阅读 · 0 评论 -
nodejs设计思想杂技二 callback 模式
回调。。。。与return回调函数如何替代return的功能?同步的函数function add(a, b) {return a + b;}异步的函数function add(a, b, callback) {callback(a + b);}同步的函数执行后return异步的函数执行完将结果放入callback中同步原创 2016-07-05 23:03:25 · 724 阅读 · 0 评论 -
nodejs 设计思想杂记一 reactor模式
开始正题,reactor 模式nodejs关于异步的本质,以及隐藏在此模式背后的故事。如单进程单线程的架构、非阻塞IO。最后看下整个nodejs平台。IO很慢,相比于CPU的处理速度来说,在非密集型计算的应用场景下,IO是一个拖慢速度的瓶颈。当然,现在正火的深度学习可以一次跑上几个月。。。。这种计算密集型的应用场景下除外。一个传统的阻塞型io的例子,线程池中每个线程处理原创 2016-07-05 22:12:08 · 3163 阅读 · 0 评论 -
软件架构所要考虑的因素
翻译 2015-12-02 11:31:44 · 722 阅读 · 0 评论 -
c++函数模板于类中的应用
class templateTest{public: template void process(func function) { function(); }}; templateTest tt; tt.process(hello);void hello(){ std::cout<<"hello"<<std::endl;}原创 2015-11-26 10:32:11 · 480 阅读 · 0 评论 -
单例模式的 模板方式实现 c++
#ifndef SINGLETON_H#define SINGLETON_H#include templateclass singleton{public:static T& Instance(){if(!pInstance){pInstance = new T;}return *pInstance;}private:singleton();static T* pInstance;};templa原创 2015-09-18 19:28:12 · 1944 阅读 · 0 评论 -
list与iterator用法实例
// list_.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include class Node{public:int id;Node(int _id){id = _id;};};int _tmain(int argc, _TCHAR* argv[]){原创 2015-09-02 10:59:20 · 4595 阅读 · 0 评论 -
c++ 设计模式之 策略模式与工厂模式结合
#include using namespace std;class COperation{public:int m_first;int m_second;virtual double getResult(){return 0;}};#define DECLARE_CLASS_CREATE(class_name) static CObject*原创 2015-08-24 15:44:20 · 1142 阅读 · 0 评论 -
c++ 设计模式之简单的工厂模式
调试环境:vs2010// test0.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include using namespace std;class COperation{public:int first;int second;virtual double getResult(){retu原创 2015-08-24 09:59:31 · 891 阅读 · 0 评论 -
nodejs 设计思想杂记四 异步控制流模式
parallelvar tasks = [...];var completed = 0;tasks.forEach(function(task) {task(function() {if(++completed === tasks.length) {finish();}});async的使用 async.series(tasks, [callback])func原创 2016-07-07 17:15:28 · 943 阅读 · 1 评论