我目前正在尝试将我们的页面模板转换为 OOP,并且我感觉我为导航类提出的内容从根本上来说并不完全正确。
- 这些方法中的一些真的属于扩展类
drawNav
吗? getMenuBar
->generateMenuBar
->结构是否generateMenuItems
过多分解?它应该只是getMenuBar
,并把所有的内容从generateMenuBar()
和generateMenuItems()
到getMenuBar()
?
我调用类和方法的方式:
$drawNav = new drawNav();
$breadcrumbTrail = $drawNav->getBreadcrumbTrail();
$menuBar = $drawNav->getMenuBar();
编码:
class drawNav {
public function __construct() {
//I’ve not nothing to put here…
}
public function getMenuBar()
{
return $this->generateMenuBar();
}
public function getBreadcrumbTrail()
{
return $this->generateBreadcrumbTrail();
}
public function getSocialMediaButtons()
{
return $this->generateSocialMediaButtons();
}
private function generateSocialMediaButtons()
{
//return the HTML code with the social media buttons
}
private function generateMenuBar()
{
//Generate the HTML containing the menu and social media buttons
$this->generateMenuItems();
$this->getSocialMediaButtons();
//Generate the HTML closing tags for the container for the menu and social media buttons
}
private function generateMenuItems()
{
//Call to the database and generate each individual menu item and its dropdown
}
private function generateBreadcrumbTrail()
{
//Generate the HTML containing the breadcrumb trail
$this->generateBreadcrumbs();
//Generate the HTML closing tags for the container for the breadcrumbtrail
}
private function generateBreadcrumbs()
{
//Call to the database and generate the pieces of the breadcrumb trail
}
}