no message
This commit is contained in:
20
Question11-VariousClasses/Ex01.php
Normal file
20
Question11-VariousClasses/Ex01.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex01 コンストラクタを使おう]
|
||||
*
|
||||
* TODO:
|
||||
* 1. 新しいファイル "Product.php" を作成し、以下の仕様に従って Product クラスを定義してください。
|
||||
* - クラス名: Product
|
||||
* - プロパティ:
|
||||
* name : 文字列
|
||||
* price : 数値
|
||||
* category : 文字列
|
||||
* - コンストラクタ:
|
||||
* __construct($name, $price, $category) を定義し、上記各プロパティに値をセットしてください。
|
||||
* 2. 本ファイル内で、require_once を使い Product.php を読み込んでください。
|
||||
* 3. 変数 $product を宣言し、Product クラスのインスタンスを生成してください。
|
||||
* 例: new Product("Laptop", 1500, "Electronics")
|
||||
* 4. 最後に、$product の各プロパティ (name, price, category) の値を出力してください。
|
||||
*
|
||||
*/
|
||||
18
Question11-VariousClasses/Ex02.php
Normal file
18
Question11-VariousClasses/Ex02.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex02 静的プロパティ・静的メソッドを使おう]
|
||||
*
|
||||
* TODO:
|
||||
* 1. 新しいファイル "Calculator.php" を作成し、以下の仕様に従って Calculator クラスを定義してください。
|
||||
* - クラス名: Calculator
|
||||
* - 静的プロパティ:
|
||||
* count : 初期値 0
|
||||
* - 静的メソッド:
|
||||
* add($a, $b) : 2つの数値の和を返す。実行時に静的プロパティ count を1増やす。
|
||||
* 2. 本ファイル内で、require_once を使い Calculator.php を読み込んでください。
|
||||
* 3. 静的メソッド add() を使い、以下の加算を2回行ってください。
|
||||
* 例: 10+20, 30+40
|
||||
* 4. それぞれの結果と、最終的な静的プロパティ count の値を出力してください。
|
||||
*
|
||||
*/
|
||||
23
Question11-VariousClasses/Ex03.php
Normal file
23
Question11-VariousClasses/Ex03.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex03 シングルトンパターン - 静的メソッドを使おう]
|
||||
*
|
||||
*
|
||||
* TODO:
|
||||
* 1. 新しいファイル "Singleton.php" を作成し、以下の仕様に従って Singleton クラスを定義してください。
|
||||
* - クラス名: Singleton
|
||||
* - プロパティ:
|
||||
* private static $instance : このクラスの唯一のインスタンスを保持する静的プロパティ
|
||||
* public $value : 任意の値を格納するためのプロパティ
|
||||
* - コンストラクタ:
|
||||
* コンストラクタは private とし、外部からの直接インスタンス生成を禁止する。
|
||||
* - 静的メソッド:
|
||||
* public static function getInstance() :
|
||||
* インスタンスが未生成なら新規に生成し、既に生成済みならそのインスタンスを返す。
|
||||
* 2. 本ファイル内で、require_once を使い Singleton.php を読み込んでください。
|
||||
* 3. 静的メソッド getInstance() を利用し、Singleton クラスのインスタンスを2つ取得してください。
|
||||
* 4. 片方のインスタンスの value プロパティに、"Hello, Singleton!" を設定し、
|
||||
* もう片方でその値を出力してください。
|
||||
*
|
||||
*/
|
||||
61
Question11-VariousClasses/index.html
Normal file
61
Question11-VariousClasses/index.html
Normal file
@@ -0,0 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>PHP コンストラクタ・静的系問題 スタートページ</title>
|
||||
<link href="../common/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>独習PHP第10章練習問題 (コンストラクタ・静的系問題) <small>クラスの基本とシングルトンパターン</small></h1>
|
||||
</div>
|
||||
|
||||
<div class="panel-group" id="accordion">
|
||||
<!-- Ex01:コンストラクタを使おう -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex01.php" target="_blank">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex01: コンストラクタを使おう (初級)
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ex02:静的プロパティ・静的メソッドを使おう -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex02.php" target="_blank">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex02: 静的プロパティ・静的メソッドを使おう (初級)
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ex03:シングルトンパターン(静的メソッド) -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex03.php" target="_blank">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex03: シングルトンパターン(静的メソッド) (上級)
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="../common/js/jquery-3.2.1.min.js"></script>
|
||||
<!-- Bootstrap Core JavaScript -->
|
||||
<script src="../common/js/bootstrap.min"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user