SlideShare a Scribd company logo
1 of 10
抽象クラス
増嶋涼平
2015 / 01 / 12
◆目次
• 抽象クラスとは
• 具体例
• メリット
• 使い方
• 注意
• まとめ
◆抽象クラスとは
クラスを継承する時に派生クラスにてオーバーライドすること
を前提として基底クラスで仮想関数を定義した時に、ひとつでも
純粋仮想関数があった場合のクラスのことを指す
①抽象クラス
◆具体例
社員クラス
- 名前
+ 出勤 ()
+ 働く ()
+ 退勤 ()
働くのは同じでも
役職によって処理は違う!!
②抽象クラス
◆具体例 解決方法
1.クラスをその都度個別で作る 2.引数を持たせ、処理を分ける
改変時に他クラスへの
影響を抑えられる
クラスを使用する側からみて
扱いが楽である
面倒であり、
ミスをしても分かりづらい
改変時に全体に
影響を及ぼす可能性がある
③抽象クラス
◆具体例 解決方法 真
社員クラス
- 名前
+ 出勤 ()←具象メソッド
+ 働く ()←抽象メソッド
+ 退勤 ()←具象メソッド
社長クラス
+ 働く () の実装
一般社員クラス
+ 働く () の実装
※抽象メソッド化により派生クラス
でのメソッドの実装を強制できる
※それぞれの役職に
合わせた処理を
実装する
④抽象クラス
◆メリット
• クラスを個別で作ることができ、
それぞれの共通のメソッドは書かなくてもよくなる
つまり、楽になる
• 抽象メソッドである「働く ()」が保障される
• 派生クラスが「社員クラス型」で統一した呼び出しができる
⑤抽象クラス
◆使い方
⑥抽象クラス
◆注意
抽象クラスは未完成なクラスのため
オブジェクトを作れません。
なので、継承して
しっかりオーバーライドしましょう。
⑦抽象クラス
◆まとめ
便利で安全。
⑧抽象クラス

More Related Content

Viewers also liked (8)

MongoDB + Spark
MongoDB + SparkMongoDB + Spark
MongoDB + Spark
 
2nd webinar - Implementation of integrated EnMS & SEAPs - SOGESCA - E.Cosenza
2nd webinar - Implementation of integrated EnMS & SEAPs - SOGESCA - E.Cosenza2nd webinar - Implementation of integrated EnMS & SEAPs - SOGESCA - E.Cosenza
2nd webinar - Implementation of integrated EnMS & SEAPs - SOGESCA - E.Cosenza
 
Pola i obwody figur płaskich
Pola i obwody figur płaskichPola i obwody figur płaskich
Pola i obwody figur płaskich
 
Juan carlos briquet los desiertos más grandes del mundo
Juan carlos briquet   los desiertos más grandes del mundoJuan carlos briquet   los desiertos más grandes del mundo
Juan carlos briquet los desiertos más grandes del mundo
 
2nd OTS - 50000&1SEAPs : Pierre Crepaux, Lorient (FR)
2nd OTS - 50000&1SEAPs : Pierre Crepaux, Lorient (FR)2nd OTS - 50000&1SEAPs : Pierre Crepaux, Lorient (FR)
2nd OTS - 50000&1SEAPs : Pierre Crepaux, Lorient (FR)
 
Cekindo regulatory for healthcare and wellness in indonesia
Cekindo regulatory for healthcare and wellness in indonesiaCekindo regulatory for healthcare and wellness in indonesia
Cekindo regulatory for healthcare and wellness in indonesia
 
Unidad III Herramientas de aprendizaje
Unidad III Herramientas de aprendizajeUnidad III Herramientas de aprendizaje
Unidad III Herramientas de aprendizaje
 
Medios de comunicación,transmisión,cable coaxial.
Medios de comunicación,transmisión,cable coaxial.Medios de comunicación,transmisión,cable coaxial.
Medios de comunicación,transmisión,cable coaxial.
 

More from Masujima Ryohei

More from Masujima Ryohei (17)

Portfolio
PortfolioPortfolio
Portfolio
 
GT1 輪講資料 Unity Standard asset Camera
GT1 輪講資料 Unity Standard asset CameraGT1 輪講資料 Unity Standard asset Camera
GT1 輪講資料 Unity Standard asset Camera
 
Castle Raid
Castle RaidCastle Raid
Castle Raid
 
Unity初心者向け
Unity初心者向けUnity初心者向け
Unity初心者向け
 
Introduce myself
Introduce myselfIntroduce myself
Introduce myself
 
THE PURSUIT DICE
THE PURSUIT DICETHE PURSUIT DICE
THE PURSUIT DICE
 
How to make Inn-fighting dice
How to make Inn-fighting diceHow to make Inn-fighting dice
How to make Inn-fighting dice
 
ぼくらのぞうきんがけVar2
ぼくらのぞうきんがけVar2ぼくらのぞうきんがけVar2
ぼくらのぞうきんがけVar2
 
巻取物語 makitori monogatari
巻取物語 makitori monogatari巻取物語 makitori monogatari
巻取物語 makitori monogatari
 
About Inheritance
About InheritanceAbout Inheritance
About Inheritance
 
Pig完成版
Pig完成版Pig完成版
Pig完成版
 
FE presentation
FE presentationFE presentation
FE presentation
 
ぼくらのぞうきんがけ
ぼくらのぞうきんがけぼくらのぞうきんがけ
ぼくらのぞうきんがけ
 
フードストライク和
フードストライク和フードストライク和
フードストライク和
 
The best army
The best army The best army
The best army
 
The best army ver2
The best army ver2The best army ver2
The best army ver2
 
Spajam2016報告会inトライデントコンピュータ専門学校
Spajam2016報告会inトライデントコンピュータ専門学校Spajam2016報告会inトライデントコンピュータ専門学校
Spajam2016報告会inトライデントコンピュータ専門学校
 

About abstract class