私は現在、ページ テンプレートを 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
}
}