Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Abstract factory C++ code

#include <iostream>

class Button
{
public:
	virtual void paint() = 0;
};
 
class WinButton : public Button 
{
public:
	void paint (){
		std::cout << " Window Button 
";
       }
};
 
class MacButton : public Button 
{
public:
	void paint (){
		std::cout << " Mac Button 
";
       }
};

class iPhoneButton : public Button 
{
public:
	void paint (){
		std::cout << " iPhone Button 
";
       }
};

class ScrollBar 
{
public:
	virtual void paint() = 0;
};
 
class WinScrollBar : public ScrollBar 
{
public:
	void paint (){
		std::cout << " Window ScrollBar 
";
       }
};
 
class MacScrollBar : public ScrollBar 
{
public:
	void paint (){
		std::cout << " Mac ScrollBar 
";
       }
};

class iPhoneScrollBar : public ScrollBar
{
public:
	void paint (){
		std::cout << " iPhone ScrollBar 
";
       }
};


class GUIFactory 
{
public:
	virtual Button* createButton () = 0;
	virtual ScrollBar* createScrollBar () = 0;
};
 
class WinFactory : public GUIFactory 
{
public:
	Button* createButton (){
		return new WinButton;
	}
	ScrollBar* createScrollBar (){
		return new WinScrollBar;
	}
};
 
class MacFactory : public GUIFactory 
{
public:
	Button* createButton (){
		return new MacButton;
	}
	ScrollBar* createScrollBar (){
		return new MacScrollBar;
	}
};
 
class iPhoneFactory : public GUIFactory 
{
public:
	Button* createButton (){
		return new iPhoneButton;
	}
	ScrollBar* createScrollBar (){
		return new iPhoneScrollBar;
	}
};

int main()
{
	GUIFactory* guiFactory;
	Button *btn;
	ScrollBar *sb;

	guiFactory = new MacFactory;
	btn = guiFactory->createButton();
	btn -> paint();
	sb = guiFactory->createScrollBar();
	sb -> paint();

	guiFactory = new WinFactory;
	btn = guiFactory->createButton();
	btn -> paint();
	sb = guiFactory->createScrollBar();
	sb -> paint();

	guiFactory = new iPhoneFactory;
	btn = guiFactory->createButton();
	btn -> paint();
	sb = guiFactory->createScrollBar();
	sb -> paint();

	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: closing a ifstream file c++ 
Cpp :: for auto c++ 
Cpp :: Shuffle String leetcode solution in c++ 
Cpp :: how to find product of a given numbers in c++ 
Cpp :: max heap insertion c++ 
Cpp :: c++ include < vs "" 
Cpp :: Arduino Real TIme Clock 
Cpp :: c++ multiline string 
Cpp :: evennumbers 1 to 100 
Cpp :: DSA 2. Complexity Analysis Google drive Educative excellent courses!!!! [Educative.io] Competitive Programming in C++ The Keys to Success 
Cpp :: round c++ 
Cpp :: custom slider cpt wordpress theme 
Cpp :: remove linked list elements leetcode 
Cpp :: valid parentheses in cpp 
Cpp :: javascript if else exercises 
Cpp :: How to see gateway on linux 
Cpp :: convert uppercase to lowercase 
Cpp :: cpp compare strings 
Cpp :: print all number between a and b in c++ 
Cpp :: c ++ The output should be (abc),(def),(ghw) 
Cpp :: wgat is duble in c++ 
Cpp :: COs trigonometric function 
Cpp :: vector int initialize with increasing numbers 
Cpp :: c++ take n number from the user and store them in array and get the max, min number of them and also find the average/summation of these numbers 
Cpp :: how to seek to the start of afile in c++ 
Cpp :: class how to call main method inheritance in c++ 
Cpp :: txt to pdf CPP 
Cpp :: CPPDEVELOPER 
Cpp :: how to run the code 
Cpp :: can you add a bool and an int 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =