Submit Search
Upload
~PHPで学ぶ~ オブジェクト指向プログラミング
•
0 likes
•
51 views
J
JunRails
Follow
オブジェクト指向プログラミング初学者向けの説明資料です。
Read less
Read more
Engineering
Report
Share
Report
Share
1 of 8
Download now
Download to read offline
Recommended
オブジェクト指向最強
オブジェクト指向最強
haganemetal
Webの勉強会#9
Webの勉強会#9
MarlboroLand
オブジェクト指向入門1
オブジェクト指向入門1
Kenta Hattori
オブジェクト指向講座
オブジェクト指向講座
Kaito Sato
オブジェクト指向の設計と実装の学び方のコツ
オブジェクト指向の設計と実装の学び方のコツ
増田 亨
javaオブジェクトシステム
javaオブジェクトシステム
Di Ai
オブジェクト指向勉強会(基礎)
オブジェクト指向勉強会(基礎)
nomuken
Cpp v3
Cpp v3
Yukinobu Yoshihara
Recommended
オブジェクト指向最強
オブジェクト指向最強
haganemetal
Webの勉強会#9
Webの勉強会#9
MarlboroLand
オブジェクト指向入門1
オブジェクト指向入門1
Kenta Hattori
オブジェクト指向講座
オブジェクト指向講座
Kaito Sato
オブジェクト指向の設計と実装の学び方のコツ
オブジェクト指向の設計と実装の学び方のコツ
増田 亨
javaオブジェクトシステム
javaオブジェクトシステム
Di Ai
オブジェクト指向勉強会(基礎)
オブジェクト指向勉強会(基礎)
nomuken
Cpp v3
Cpp v3
Yukinobu Yoshihara
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
More Related Content
Featured
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Featured
(20)
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
~PHPで学ぶ~ オブジェクト指向プログラミング
1.
~PHPで学ぶ~ オブジェクト指向プログラミング じゅん@Railsエンジニア(勉強中)
2.
PHPで学ぶオブジェクト指向プログラミング ①オブジェクト指向プログラミングとは? 「オブジェクト指向の考え方を取り入れ、オブジェクトを組み立てるように表現して、 システムを構築する」プログラミング手法です。 オブジェクトの振る舞いに矛盾がないよう、定義する。 ②オブジェクトとは? オブジェクト指向の言葉を生み出した計算機科学者アラン・ケイの言葉を引用。 “すべてはオブジェクトである。” “どのオブジェクトもクラスのインスタンスであり、クラスもまたオブジェクトである。” 私は、「オブジェクトとは現実世界の全てモノ。クラスとインスタンスはオブジェクトに含まれる。 クラス != インスタンス
」だと理解しました。間違えていたら、ご指摘下さい、、、 ③クラスとインスタンスの関係 クラス :設計書 インスタンス:クラスを実体化したもの ※例を右図に示す。 クラス:エンジニア インスタンス:エンジニアのJunさん 実体化
3.
PHPで学ぶオブジェクト指向プログラミング (1)クラスとインスタンス ・クラス定義:オブジェクトのメソッド(機能)とプロパティ(属性)を定義する。 <?php class Engineer { public
$name; public $age; public function showName() { echo “エンジニアの{$this->name}です!”, “\n”; } public function showAge() { echo “年齢は {$ this-> age}です!”, “\n”; } } ?> Engineerの名前・得意言語 といった属性を定義する。 文字列の出力等、実行できる処理 をメソッドとして定義する。 ・インスタンスの生成と値の設定 $engineer = new Engineer(“ジュン” , 26); $engineer ->showName() ; $engineer ->showLanguage() ; 出力 ⇒ エンジニアのジュンです! 年齢は26歳です! ・インスタンスメソッドの実行 ファイル名: Engineer.php ※コンストラクタの記述は割愛
4.
PHPで学ぶオブジェクト指向プログラミング (2)クラスの継承 既存のクラスを拡張するように自身のクラスを定義することが可能 親クラス子クラス <?php require_once(“Engineer.php”); class WebEngineer extends
Engineer { public function pullRequest() { echo “{$this->name}がプルリクエストしました!”, “\n”; } } ?> ファイル名:WebEngineer.php extends Engineerクラス定義 ファイルの読み込み Engineerクラスを継承して Gitクラスを定義 継承によりEngineerクラスの ${name}プロパティが使用可 インスタンスの生成と値の設定 $engineer = new WebEngineer(“ジュン”); $engineer-> pullRequest(); 出力 ⇒ ジュンがプルリクエストしました! インスタンスメソッドの実行 子クラスは、親クラスから プロパティとメソッドを継承する
5.
<?php require_once(“Git.php”); Class Engineer { public
$name; public $language; use Git1, Git2; ・ ・ ・ } ?> PHPで学ぶオブジェクト指向プログラミング (3)トレイト PHPでは、複数のクラスを継承する多重継承がサポートされていない。 そこで、トレイトの機能を使うことで複数のトレイトからメソッドを引き継ぐことができる。 トレイトの定義 <?php trait Git1{ function merge(){ echo “プルリクエストをマージしました!”, “\n”; } } trait Git2{ function comment(){ echo “プルリクエストにコメントしました!”, “\n”; } } トレイトの定義 ファイル名:Git.php トレイトの利用 ファイル名:Engineer.php トレイトの利用を宣言 複数のトレイトを指定可 インスタンスの生成とメソッドの実行 $engineer = new Engineer(); $engineer -> merge(); $engineer -> comment(); プルリクエストをマージしました! プルリクエストにコメントしました! 出力
6.
<?php require_once(“Insterface.php”); Class Engineer implements
Git{ public function pullrequest() { echo “プルリクエストしました!”, “\n”; } public function merge() { echo “マージしました!”, “\n”; } } ?> PHPで学ぶオブジェクト指向プログラミング (4)インターフェース クラスで実装すべきメソッドを規格として定めることができる。 不特定のクラスで、共通のメソッドを定義したい場合等に使用する。 インターフェースの定義 <?php Interface Git { function pullrequest() ; function merge() ; } ?> ファイル名:Interface.php インターフェースの利用 ファイル名:Engineer.php Gitインターフェースの規格では、 pullrequest()、merge()を実装しな ければならない Gitインターフェースで 指定されているメソッドを実装 インスタンスの生成とメソッドの実行 $engineer = new Engineer(); $engineer -> conflict(); $engineer -> merge(); プルリクエストしました! マージしました! 出力
7.
PHPで学ぶオブジェクト指向プログラミング (5)抽象クラス 抽象メソッドがあるクラスを、抽象クラスという。 抽象クラスを継承した子クラスで、抽象メソッドをオーバーライドして使用できる。 <?php require_once(“Abstract.php”); Class Engineer extends
Git { public function maerge() { echo “マージしました!”, “\n”; } } ?> 抽象クラスの定義 <?php abstract class Git { abstract function merge(); } ?> ファイル名:Abstract.php 抽象クラスの利用 ファイル名:Engineer.php インスタンスの生成とメソッドの実行 $developer1 = new Engineer(); $ developer1-> merge(); マージしました! 出力 抽象メソッドの定義 継承した抽象メソッドの オーバーライド
8.
PHPで学ぶオブジェクト指向プログラミング 先輩からのアドバイス ・クラスの名前付けは、とても重要。継承関係等を意識したクラス名をつけるべき ・オブジェクトの振る舞いに矛盾がないように定義する ・オブジェクト指向を意識しながら、標準クラス等の優れたコードをリーディングすると効果的 ・難しく考えすぎないほうがいい 参考情報 ・大重美幸(2018) 『詳細!PHP7 +
MySQL 入門ノート』大日本印刷株式会社 ・PHPでインターフェイスと抽象クラスを使う https://qiita.com/nogson/items/e6575d6617f854ed6e25
Download now