<?php /** * */ class Automobile { private $vehicle_make; private $vehicle_model; public function __construct($make,$model) { # code... $this->vehicle_make = $make; $this->vehicle_model = $model; } public function get_make_and_model(){ return $this->vehicle_make . ‘ ‘. $this->vehicle_model; } } /** * */ class AutomobileFactory { public function create($make,$model){ return new Automobile($make,$model); } } $veyron = AutomobileFactory::create(‘chuzha‘,‘love you‘); print_r($veyron->get_make_and_model()); ?>
值得注意的是调用静态方法:
AutomobileFactory::create
时间: 2024-10-13 03:08:39