LoginSignup
0
2

More than 5 years have passed since last update.

オブジェクト指向:クラスとインスタンスについて

Last updated at Posted at 2018-08-13

オブジェクト指向とは

「モノ」を組み立てるように表現して、コンピュータに動作させること

インスタンスとは

クラス⇒枠組み
インスタンス⇒クラスに実際にデータを格納したもの
クラスという設計図をもとに実体を作成する

料理で例えると・・・
クラス⇒レシピ
インスタンス⇒レシピをもとに作られた料理

クラスの継承

クラスのプロパティを他のクラスを引き継ぐ、

クラスの中身

class Tire{//クラスの定義
//変数の定義
public $weight;
public $size;

//関数の定義
public function _constract($weight,$size){
   $weight=$this->weight;
   $size=$this-$size;

public function tireData($weight,$size)
 {
    echo "重さは".weight."kgです。大きさは".$size."cmです" 
"文字列".変数."文字列"

これによって
タイヤの重さ・大きさなどの構造を設計し、出力する準備が整った、だがまだ準備しただけで実際に出力はされない

インスタンスの中身

$tire=new Tire();//Tireクラスのコピー(インスタンスを作成)

$tire->tireData(15,20);//タイヤの重さは15kg,大きさは20cm

インスタンスの実行により実体となる

名前空間の指定方法

場所\クラス名: :メソッド

0
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2