SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
オブジェクト指向プログラミング
OOPの三原則

(人間の処理能力の限界を超える)
 複雑さをなるべく軽減する!

カプセル化

継承

ポリモーフィズム
カプセル化


データと手続きのまとまり

処理の抽象化:構造化プログラミング
→ 順接,条件分岐,反復 , サブルーチン


データの抽象化:カプセル化
ブラックボックス化

      内部の処理はわからない


                    入力と出力のみ決まっていて、内部の処
1+1                 理は隠   している

                    ブラックボックス化することで、プログ
                    ラム全体の見通しがよくなる

                    変更を必要最低限に抑えることができる
 2
スコープ


プログラムの複雑さを軽減する

変数への不正なアクセスを遮断できる

汎用的な変数 / メソッドなどでない限りスコープ
は小さく
継承


似たような性質を括りだして同じ種類のオ
ブジェクトの管理(便利)

単継承の限界と問題点

多重継承の注意点
クラス

                                            人間
                              インスタンス      クラス
                              (=オブジェクト)



               name: 阿良々木暦

                method : 話す
                method : 呼吸

                                             name


name: 八九時真宵   インスタンス                      method : 話す
              (=オブジェクト)
                                          method : 呼吸
method: 呼吸

method: 話す
スーパークラス
     猫             人間
                                    生物
 クラス             クラス
                                   クラス
                               継
                               承   スーパークラス


    name            name              data

 method : 呼吸     method : 呼吸       method : 呼吸

 method : 鳴く     method : 話す



生物クラスだけじゃなく、他のクラスにも属してるはず
多重継承
プログラマ
 クラス           俺             生物
          継   クラス           クラス
スーパークラス
          承             継
             承
スパゲッティ継承になる可能性がある
                            スーパークラス


 学生                     福岡県民
          継         継
クラス                     クラス
          承         承
スーパークラス                 スーパークラス
インターフェース, Mix-in etc.




静的型言語と動的型言語における多重継承
による複雑さ軽減の方法

静的型言語と動的型言語で、どのように
ポリモーフィズムを実現しているか
インターフェース                          (Javaのような静的言語の場合)



                        設計の概要を共有できる                生物
魚型&生物型              同じ型として扱うことができる
                                               インターフェース




                  人間型&生物型
method : 動く(泳ぐ)
                                                 method : 動く
method : (エラ)呼吸
                                                 method : 呼吸

オーバーライド
  して実装                               コンパイル時の静的な型決定と
                   method : 動く(歩く)
                                     実行時の動的な型決定の両立
                   method : (肺)呼吸
                                     →ポリモーフィズムの実現
Mix-in(Rubyのような動的言語の場合)
 多重継承の変形型(制限付きの多重継承?)

 クラスの木構造は保ったまま




(動的型言語では)   Duck Typingで多様性を実現
Duck Typing

 If it walks like a duck and quacks like a duck,
                 it must be a duck.

クラスの継承関係やインターフェースなどは考慮せず、どのよ
うなメソッドを持っているかのみに関心する

型宣言などはせず、したいこと(プログラムの本質)に集中して簡
潔なコードを書ける

書きやすい & 読みやすい

動的型言語ならではの柔軟性 , スピーディな記述
哲学(規約 / 概念 )

      Ruby on Railsの基本理念

CoC
Convention over Configuration. 制約より規約

DRY
Don’t Repeat Yourself.
Convention over Configuration

 制約より規約

 アプリケーションの慣例に従わない部分だけ指定
 すればよい

 開発者は規約にしたがってコーディングし、規約
 に反するところだけ別に記述すればよい

 プログラムに一貫性がでてくる
DRY( Don’t Repeat Yourself )



情報の重複をふせぐ考え方 ⇔OAOO(Once and Only Once)

情報の引き出しに対しては寛容

他のコンポーネントに対しての依存を少なくできる

誤用すると密結合を生む可能性がある

Más contenido relacionado

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)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 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd 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 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 IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...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
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 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 ChatGPTEverything 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 EngineeringsProduct 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 HealthHow 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.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO 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)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 2024How 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 InsightsSocial 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 2024Trends 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 summary5 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 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 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 IntentGoogle'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 How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe 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...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Oop