Bridge mode

#include<iostream>
using namespace std;

class Engine
{
public:
	virtual void InstallEngine() = 0;
};

class Engine4400cc :public Engine
{
public:
	virtual void InstallEngine()
	{
		cout << "I am a 4400cc engine, the installation is complete!" << endl;
	}
};

class Engine4500cc :public Engine
{
	virtual void InstallEngine()
	{
		 cout << "I am a 4500cc engine, the installation is complete!" << endl;
	}
};

class Car
{
public:
	Car(Engine *engine)
	{
		m_engine = engine;
	}
	virtual void InstallEngine() = 0;
protected:
	Engine *m_engine;
};

class BMW5 :public Car
{
public:
	BMW5(Engine*engine) :Car(engine){}
	
	virtual void InstallEngine()
	{
		 cout << "I am BMW5" << endl;
		m_engine->InstallEngine();
	}
};

class BMW6 :public Car
{
public:
	BMW6(Engine*engine) :Car(engine){}
	virtual void InstallEngine()
	{
		 cout << "I am BMW6" << endl;
		m_engine->InstallEngine();
	}
};

void main()
{
	Engine *engine = NULL;
	Car *car = NULL;

	engine = new Engine4500cc;
	car = new BMW6(engine);

	car->InstallEngine();
	delete car;

	car = new BMW5(engine);
	car->InstallEngine();
	delete car;

	delete engine;
}

Intelligent Recommendation

Initialization block, class initialization block (static code block), the order in which objects are created

Initialization block The strength initialization block is "illusion". After a class is compiled, the code block disappears and is restored to all the code of each constructor. Function: So t...

Spring WebSocket configuration instructions, method functions and execution order

Spring version 5.0 xml configuration Note: The front-end WS protocol can request /websocket configured in the root directory of the project, and the path configured in the blue part of the code block ...

4.JavaScript implementation table interlaced discoloration

The CSS code is as follows: HTML code is as follows The JS code is as follows:...

Hive and HBase table of data migration

Preamble: The company recently migrated data, do a test to verify the command. A, Hive section Two, HBase table  ...

Quick sort (refer to "Introduction to Algorithms", the core code is only 18 lines)

Preface Generally speaking, quick sort is an advanced insertion sort, but although many methods on the Internet are easy to understand, it is difficult to see the similarities with basic insertion sor...

More Recommendation

texts = [[word for word in document.split ()] for document in documents] forms What does this mean?

texts=[[word for word in document.split()]for document in documents] He can be seen as a double for the cycle, but there is a list of conversion we look at a simple Equivalent to: Just a little less t...

laravel(4.2) +Zizaco

Procedure: https: //github.com/Zizaco/entrust/tree/1.0 This blog said quite detailed: http: //blog.boolw.com/ p = 241? Step simplified 1. Add the following code (note: "laravel / framework":...

【vue】How to create a new vue project in cmd through vue-cli (vue scaffolding)

【vue】How to create a new vue project in cmd 1. First open cmd and use the cd command to go to the folder where the project is created. 2. Generate a project with a specified project name through the v...

Design pattern [Abstract Factory Pattern]

Abstract factory pattern Abstract Factory Pattern is to create other factories around a super factory. This super factory is also called the factory of other factories. This type of design pattern is ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top