Template method pattern: Difference between revisions

Content deleted Content added
Imtron (talk | contribs)
m External links: Updated ___domain from devshed.com to devshed.org
No edit summary
Line 106:
$game = new Mario();
$game->play();
</syntaxhighlight>
 
==C++ example==
<syntaxhighlight lang="cpp">
#include<iostream>
 
class BaseClass abstract {
protected:
virtual void someMethod() = 0;
public:
void ThisIsTempleteMethod() { someMethod(); }
};
 
class ExtendedClass_one : public BaseClass {
void someMethod() override {
puts("[ExtendedClass_one] Re-Difine method here.");
}
};
class ExtendedClass_two : public BaseClass {
void someMethod() override {
puts("[ExtendedClass_two] Re-Difine method here.");
}
};
 
int main() {
 
BaseClass* one = new ExtendedClass_one;
one->ThisIsTempleteMethod();
 
BaseClass* two = new ExtendedClass_two;
two->ThisIsTempleteMethod();
 
return 0;
}
</syntaxhighlight>