复制代码 代码如下:
/**
* 模板模式
*
* 定义一个操作中的算法骨架,而将一些步骤延迟到子类中,使得子类可以不改变一个算法的结构可以定义该算法的某些特定步骤
*
*/
abstract class TemplateBase
{
public function Method1()
{
echo "abstract Method1
";
}
public function Method2()
{
echo "abstract Method2
";
}
public function Method3()
{
echo "abstract Method3
";
}
public function doSomeThing()
{
$this->Method1();
$this->Method2();
$this->Method3();
}
}
class TemplateObject extends TemplateBase
{
}
class TemplateObject1 extends TemplateBase
{
public function Method3()
{
echo "TemplateObject1 Method3
";
}
}
class TemplateObject2 extends TemplateBase
{
public function Method2()
{
echo "TemplateObject2 Method2
";
}
}
// 实例化
$objTemplate = new TemplateObject();
$objTemplate1 = new TemplateObject1();
$objTemplate2 = new TemplateObject2();
$objTemplate->doSomeThing();
$objTemplate1->doSomeThing();
$objTemplate2->doSomeThing();

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools