时间:2021-07-01 10:21:17 帮助过:10人阅读
//实现工厂方法interfaceabstracted{publicfunctionrealCreate();
}
//女人类classWuman{publicfunctionaction(){echo"这是女人";
}
}
//男人类classMan{publicfunctionaction(){echo"这是男人";
}
}
//创建女人classwomanCreatorimplementsabstracted{public$chromosome;//染色体publicfunctionrealCreate(){if($this->chromosome == "xx"){
returnnew Wuman();
}
}
}
//创建男人classmanCreatorimplementsabstracted{public$chromosome;//染色体publicfunctionrealCreate(){if($this->chromosome == "xy"){
returnnew Man();
}
}
}
//人类工厂classPersonFactory{publicfunctioncreate($category){$method = "{$category}Creator";
return$create = new$method();
}
}
$create = new PersonFactory();//创造人类$instance = $create->create('woman');//创造女人$instance->chromosome = "xx";//女性染色体$instance->realCreate()->action();
?>
').addClass('pre-numbering').hide();
$(this).addClass('has-numbering').parent().append($numbering);
for (i = 1; i <= lines; i++) {
$numbering.append($('').text(i));
};
$numbering.fadeIn(1700);
});
});
以上就介绍了php中工厂方法的两个特殊例子,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。