わかりました、わかっています。私は知っています...これはおそらく簡単なものです。しかし、私はOOPに非常に慣れていないので、コードをより効率的にリサイクルする方法を学びたいと思っています。
私はphpにクラスを持っていて、それからそのように前のクラスを拡張する別のクラスを持っています
class team {
private $league;
private $team;
public $year = 2013;
function getTeamSeasonRecord($league, $team) {
// Get given's team record thus far
$this->record = $record;
return $record;
}
class game extends team{
public function __construct()
{
global $db;
if($game_league == "mlb")
{
$table = "current_season_games";
} else
{
$table = "".$game_league."_current_season_games";
}
$query = "SELECT * FROM ".$table." WHERE game_id = :game_id";
$stmt = $db->prepare($query);
$stmt->execute(array(':game_id' => $game_num));
$count = $stmt->rowCount();
$this->games_count = $count;
if($count == 1)
{
$this->game_league = $game_league;
$this->game_num = $game_num;
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$home_team = $row['home_team'];
$away_team = $row['away_team'];
$game_int = $row['game_date_int'];
$game_date = $row['game_date'];
$game_time = $row['game_time'];
}
$this->home_team = $home_team;
$this->away_team = $away_team;
$this->game_int = $game_int;
$this->game_date = $game_date;
$this->game_time = $game_time;
}
}
$team_class = new team($this->game_league, $this->home_team, 2013);
$record = $team_class->getTeamSeasonRecord($this->game_league, $this->home_team);
$this->team_record -> $record;
}
「ゲーム」というタイトルのクラスは「チーム」というタイトルのクラスの拡張であるため、ゲームクラスはチームクラスのスコープ内のすべての機能にアクセスできませんか?チームクラスで記述されたgetTeamSeasonRecord()関数は、任意のチームのレコードを検索します。しかし、ゲームクラスには2つのチームがあります。1.)ホームチームと2.)アウェイチーム。ホームチームとアウェイチームの両方の記録を見つける必要があります。両方のクラスで同じ機能を持つ必要がないように、コードをリサイクルするにはどうすればよいですか?