Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

template design pattern

#include<iostream>

class BaseClass abstract {
protected:
	virtual void someMethod() = 0;
public:
	void ThisIsTemplateMethod() { someMethod(); }
};

class ExtendedClass_one : public BaseClass {
	void someMethod() override {
		puts("[ExtendedClass_one] Re-Define method here.");
	}
};
class ExtendedClass_two : public BaseClass {
	void someMethod() override {
		puts("[ExtendedClass_two] Re-Define method here.");
	}
};

int main() {

	BaseClass* one = new ExtendedClass_one;
	one->ThisIsTemplateMethod();

	BaseClass* two = new ExtendedClass_two;
	two->ThisIsTemplateMethod();

	return 0;
}
Source by en.wikipedia.org #
 
PREVIOUS NEXT
Tagged: #template #design #pattern
ADD COMMENT
Topic
Name
5+6 =