首页 > 其他分享 >cpp: Bridge Pattern

cpp: Bridge Pattern

时间:2023-06-03 23:00:17浏览次数:37  
标签:Bridge DuJewelryBridgePattern Gold Pattern namespace char cpp using include

 

/*****************************************************************//**
 * \file   Gold.h
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
#pragma once
#ifndef GOLD_H 
#define GOLD_H 

#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
#include <vector>

using namespace std;




namespace DuJewelryBridgePattern
{

	/// <summary>
	/// 黄金
	/// </summary>
	class Gold
	{

	public:
		/// <summary>
		/// 镶㠌
		/// </summary>
		/// <param name="pInlayName"></param>
		void metallurgy(const char* pInlayName)
		{
			int iLen = 100;
			//char du[100]=pInlayName;
			
			//char** ptr;
			//ptr = &pInlayName;

			char* pData = parseDesgin(pInlayName, iLen);
			if (iLen > 0)
			{
				//char* p;
				//*p = ' ';
				// *p= *pData;
				// << *p
				cout<<"["<< pInlayName << "]*" << "显示pData所指向的缓冲区中的黄金数据。" << endl;
				//......
				delete pData; //模拟代码中因为pData的内存是new出来的,这里需要释放该内存
			}
		}
		/// <summary>
		/// 
		/// </summary>
		virtual ~Gold() {} //做父类时析构函数应该为虚函数
	private:
		//根据文件名分析文件内容,每个子类因为黄金冶炼不同,会有不同的读取和处理代码 Inlay

		/// <summary>
		/// 设计
		/// </summary>
		/// <param name="pInlayName"></param>
		/// <param name="iLen"></param>
		/// <returns></returns>
		virtual char* parseDesgin(const char* pInlayName, int& iLen) = 0;

	};
}

#endif

/*****************************************************************//**
 * \file   GoldGrace.h
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
#pragma once
#ifndef GOLDGRACE_H 
#define GOLDGRACE_H 

#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>

#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
#include <vector>

#include "Gold.h"


using namespace std;




namespace DuJewelryBridgePattern
{

	/// <summary>
	/// 优雅
	/// </summary>
	class GoldGrace:public Gold
	{

	private:
		/// <summary>
		/// 设计
		/// </summary>
		/// <param name="pInlayName"></param>
		/// <param name="iLen"></param>
		/// <returns></returns>
		virtual char* parseDesgin(const char* pInlayName, int& iLen)
		{
			
			cout << "Grace 优雅:韧性和延展性高,不受传统黄金材质限制,可打造出优雅时尚的造型;";
			iLen = 100;
			char* presult = new char[iLen];
			return presult;
		}


	};

}


#endif


/*****************************************************************//**
 * \file   GoldGlorious.h
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
#pragma once
#ifndef GOLDGLORIOUS_H
#define GOLDGLORIOUS_H 

#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
#include <vector>

#include "Gold.h"

using namespace std;




namespace DuJewelryBridgePattern
{

	/// <summary>
	/// 璀璨
	/// </summary>
	class GoldGlorious :public Gold
	{

		virtual char* parseDesgin(const char* pInlayName, int& iLen)
		{

			cout << "Glorious 璀璨:纯金材质,拥有天然的24K夺目金色,不易褪色,璀璨夺目:";
			iLen = 100;
			char* presult = new char[iLen];
			return presult;
		}

	};
}

#endif


/*****************************************************************//**
 * \file   GoldGentle.h
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
#pragma once
#ifndef GOLDGENGLE_H
#define GOLDGENGLE_H 

#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
#include <vector>

#include "Gold.h"

using namespace std;




namespace DuJewelryBridgePattern
{

	/// <summary>
	/// 高尚
	/// </summary>
	class GoldGentle :public Gold
	{

		virtual char* parseDesgin(const char* pInlayName, int& iLen)
		{

			cout << "Gentle 高尚:达到足金以上的含金量,更具价值;";
			iLen = 100;
			char* presult = new char[iLen];
			return presult;
		}

	};
}
#endif


/*****************************************************************//**
 * \file   GoldGenius.h
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
#pragma once
#ifndef GOLDGENIUS_H
#define GOLDGENIUS_H 

#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
#include <vector>

#include "Gold.h"

using namespace std;




namespace DuJewelryBridgePattern
{
	/// <summary>
	/// 天赋
	/// </summary>
	class GoldGenius :public Gold
	{
		virtual char* parseDesgin(const char* pInlayName, int& iLen)
		{

			cout << "Genius 天赋:做工精细,技术前卫,艺术性强,具有先天工艺优势;";
			iLen = 100;
			char* presult = new char[iLen];
			return presult;
		}


	};

}

#endif


/*****************************************************************//**
 * \file   GoldGusty.h
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
#pragma once
#ifndef GOLDGUSTY_H
#define GOLDGUSTY_H 

#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
#include <vector>

#include "Gold.h"

using namespace std;




namespace DuJewelryBridgePattern
{

	/// <summary>
	/// 坚定
	/// </summary>
	class GoldGusty :public Gold
	{

		virtual char* parseDesgin(const char* pInlayName, int& iLen)
		{

			cout << "Gusty 坚定:硬度高,不易变形,且更加轻便;";
			iLen = 100;
			char* presult = new char[iLen];
			return presult;
		}

	};

}
#endif

/*****************************************************************//**
 * \file   GeovinDu.h
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
#pragma once
#ifndef GEOVINDU_H 
#define GEOVINDU_H 

#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>

#include "Gold.h"
#include "GoldGenius.h"
#include "GoldGentle.h"
#include "GoldGlorious.h"
#include "GoldGrace.h"
#include "GoldGusty.h"



using namespace std;




namespace DuJewelryBridgePattern
{

	/// <summary>
	/// 
	/// </summary>
	class GeovinDu
	{

	private:

	public:

		/// <summary>
		/// 
		/// </summary>
		void displaySimple();


	};

}

#endif

/*****************************************************************//**
 * \file   GeovinDu.cpp
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
#include "GeovinDu.h"
using namespace std;




namespace DuJewelryBridgePattern
{


	/// <summary>
	/// 
	/// </summary>
	void GeovinDu::displaySimple()
	{

		DuJewelryBridgePattern::Gold* pJewelry= new DuJewelryBridgePattern::GoldGrace();
		pJewelry->metallurgy("镶嵌蓝宝石");

		DuJewelryBridgePattern::Gold* pJewelry2 = new DuJewelryBridgePattern::GoldGlorious();
		pJewelry2->metallurgy("镶嵌绿宝石");

		DuJewelryBridgePattern::Gold* pJewelry3 = new DuJewelryBridgePattern::GoldGentle();
		pJewelry3->metallurgy("镶嵌红宝石");

		DuJewelryBridgePattern::Gold* pJewelry4 = new DuJewelryBridgePattern::GoldGenius();
		pJewelry4->metallurgy("镶翡翠玉石");

		DuJewelryBridgePattern::Gold* pJewelry5 = new DuJewelryBridgePattern::GoldGusty();
		pJewelry5->metallurgy("镶嵌玛瑙");

		//释放资源
		delete pJewelry;
		delete pJewelry2;
		delete pJewelry3;
		delete pJewelry4;
		delete pJewelry5;
	






	}

}

  

调用:

/*****************************************************************//**
 * \file   ConsoleDuBridgePattern.cpp
 * \brief  桥接模式  Bridge Pattern C++ 14
 * 2023年6月3日 涂聚文 Geovin Du Visual Studio 2022 edit.
 * \author geovindu
 * \date   June 2023
 *********************************************************************/
// ConsoleDuBridgePattern.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#define _UNICODE

#include <iostream>
#include "GeovinDu.h"


#ifdef _DEBUG   //只在Debug(调试)模式下
#ifndef DEBUG_NEW
#define DEBUG_NEW new(_NORMAL_BLOCK,__FILE__,__LINE__) //重新定义new运算符
#define new DEBUG_NEW
#endif
#endif

//#include <boost/type_index.hpp>
using namespace std;
using namespace DuJewelryBridgePattern;


int main()
{
    std::cout << "Hello World!涂聚文 Geovin Du\n";


    GeovinDu geovin;
    geovin.displaySimple();

    cout << "********" << endl;


    system("pause");

    return 0;

}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
#define UNICODE

  

输出:

Hello World!涂聚文 Geovin Du
Grace 优雅:韧性和延展性高,不受传统黄金材质限制,可打造出优雅时尚的造型;[镶嵌蓝宝石]*显示pData所指向的缓冲区中的黄金数据。
Glorious 璀璨:纯金材质,拥有天然的24K夺目金色,不易褪色,璀璨夺目:[镶嵌绿宝石]*显示pData所指向的缓冲区中的黄金数据。
Gentle 高尚:达到足金以上的含金量,更具价值;[镶嵌红宝石]*显示pData所指向的缓冲区中的黄金数据。
Genius 天赋:做工精细,技术前卫,艺术性强,具有先天工艺优势;[镶翡翠玉石]*显示pData所指向的缓冲区中的黄金数据。
Gusty 坚定:硬度高,不易变形,且更加轻便;[镶嵌玛瑙]*显示pData所指向的缓冲区中的黄金数据。
********
请按任意键继续. . .

  

 

标签:Bridge,DuJewelryBridgePattern,Gold,Pattern,namespace,char,cpp,using,include
From: https://www.cnblogs.com/geovindu/p/17454935.html

相关文章

  • log4j2<PatternLayout>子节点浅析
    log4j2<PatternLayout>子节点浅析 首先声明本文并不教您怎么用log4j2,仅仅只对<PatternLayout>子节点进行说明。要看懂本文需要对log4j2有一定的了解,至少能够知道<Appenders>、<Layouts>和<Loggers>的区别。本文主要参考对象为log4j2官方手册:《ApacheLog4j2v.2.1User'sGuide......
  • cpp: Proxy Pattern
     /*****************************************************************//***\fileGoldWebSite.h*\brief代理模式ProxyPatternC++14*2023年5月31日涂聚文GeovinDuVisualStudio2022edit.*\authorgeovindu*\dateMay2023******************......
  • kibana智能检索发送多次_msearch —— 配置index pattern,同时设置时间段,就知道到底是
    kibanasite/elasticsearch/log-*/_field_stats?level=indices   返回:{"_shards":{"total":600,"successful":600,"failed":0},"indices":{"log-2017.11.22-19-192.168.2.3-93004":{"fields":{"Rec......
  • 解释器模式(Interpreter Pattern)
    解释器模式(InterpreterPattern)一、定义解释器模式(InterpreterPattern)提供了评估语言的语法或表达式的方式,它属于行为型模式。这种模式实现了一个表达式接口,该接口解释一个特定的上下文。这种模式被用在SQL解析、符号处理引擎等。给定一个语言,定义它的文法的一种表示,并定义......
  • cassandra cpp driver中bind list——用cass_statement_bind_collection函数
     CassErrorinsert_into_collections(CassSession*session,constchar*key,constchar*items[]){CassErrorrc=CASS_OK;CassStatement*statement=NULL;CassFuture*future=NULL;CassCollection*collection=NULL;constchar**item=NULL;c......
  • Abstract Factory Pattern 抽象工厂模式简介与 C# 示例【创建型】【设计模式来了】
    〇、简介1、什么是抽象工厂模式?一句话解释:  通过对抽象类和抽象工厂的一组实现,独立出一系列新的操作,客户端无需了解其逻辑直接访问。抽象工厂模式(AbstractFactoryPattern)是一种创建型模式。它用于创建一组相关对象的家族。强调的是一组对象之间的协作关系,而不是单个对象之......
  • vscode配置单个cpp文件打断点的文件
    (51条消息)【工具】VScode设置断点调试(以cpp为例)_vdcode运行断点cpp_沙diao网友的博客-CSDN博客launch.json内容{//UseIntelliSensetolearnaboutpossibleattributes.//Hovertoviewdescriptionsofexistingattributes.//Formoreinformation,......
  • ubuntu22 kvm bridge
    KVM是基于内核的虚拟机(Kernel-basedVirtualMachine)的首字母缩写,这是一项集成在内核中的开源虚拟化技术。它是一种类型一(裸机)的管理程序(hypervisor),可以使内核能够作为一个裸机管理程序(bare-metalhypervisor)。在KVM之上可以运行Windows和Liunx虚拟机。每个虚拟机......
  • cpp: State Pattern
     /*****************************************************************//***\fileGold.h*\briefStatePattern状态模式C++14*2023年5月29日涂聚文GeovinDuVisualStudio2022edit.*\authorgeovindu*\dateMay2023************************......
  • Factory Method Pattern 工厂方法模式简介与 C# 示例【创建型】【设计模式来了】
    〇、简介1、什么是工厂方法模式?一句话解释:  实体类和工厂类均为单独实现,不影响已实现的类,方便扩展。工厂方法模式(FactoryMethodPattern)是一种创建型模式,它允许客户端通过工厂方法来创建对象,而不是直接使用构造函数。这样可以让客户端代码更加灵活,同时保持实现的独立性。工......