Upgrade to Pro — share decks privately, control downloads, hide ads and more …

本当は面白いオブジェクト指向のとっておきのお話

 本当は面白いオブジェクト指向のとっておきのお話

はじめてのIT勉強会

January 29, 2018
Tweet

More Decks by はじめてのIT勉強会

Other Decks in Technology

Transcript

  1. ϓϩάϥϛϯά΍ͬͯΔͱग़͖ͯ·͢ΑͶ public class Main{ public static void main(String args[]){ methodA();

    methodB(); methodC(); methodD(); } void methodA(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodB(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodC(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodD(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } public class Main{ public static void main(String args[]){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ ɾɾɾ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } .BJOKBWB .BJOKBWB
  2. NBJOϝιουʹશ෦ॻ͘ͱɺ͙ͪΌ͙ͪΌ public class Main{ public static void main(String args[]){ methodA();

    methodB(); methodC(); methodD(); } void methodA(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodB(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodC(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodD(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } public class Main{ public static void main(String args[]){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ ɾɾɾ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } .BJOKBWB .BJOKBWB
  3. ͔ͩΒɺʮϝιουʯʹ෼ׂ͢Δɻ public class Main{ public static void main(String args[]){ methodA();

    methodB(); methodC(); methodD(); } void methodA(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodB(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodC(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } void methodD(){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } public class Main{ public static void main(String args[]){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ ɾɾɾ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } .BJOKBWB .BJOKBWB
  4. ͞ΒʹͦΕͰ΋ͪ͝Όͪ͝Ό͢Δ͔Β public class Main{ public static void main(String args[]){ ClassA.methodA();

    ClassA.methodB(); ClassB.methodC(); ClassB.methodD(); } } public class Main{ public static void main(String args[]){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ ɾɾɾ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } public class ClassA{ void methodA(){…} void methodB(){…} } public class ClassB{ void methodC(){…} void methodD(){…} } .BJOKBWB $MBTT"KBWB $MBTT#KBWB .BJOKBWB
  5. ΋ͬͱେ͖ͳʮΫϥεʯͱ͍͏୯Ґʹ public class Main{ public static void main(String args[]){ ClassA.methodA();

    ClassA.methodB(); ClassB.methodC(); ClassB.methodD(); } } public class Main{ public static void main(String args[]){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ ɾɾɾ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } public class ClassA{ void methodA(){…} void methodB(){…} } public class ClassB{ void methodC(){…} void methodD(){…} } .BJOKBWB $MBTT"KBWB $MBTT#KBWB .BJOKBWB
  6. ෼ׂ͢ΔͷͰͨ͠ɻ public class Main{ public static void main(String args[]){ ClassA.methodA();

    ClassA.methodB(); ClassB.methodC(); ClassB.methodD(); } } public class Main{ public static void main(String args[]){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ ɾɾɾ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } public class ClassA{ void methodA(){…} void methodB(){…} } public class ClassB{ void methodC(){…} void methodD(){…} } .BJOKBWB $MBTT"KBWB $MBTT#KBWB .BJOKBWB
  7. Ͱɺޓ͍ʹݺͼ߹͏ͷͰͨ͠ɻ public class Main{ public static void main(String args[]){ ClassA.methodA();

    ClassA.methodB(); ClassB.methodC(); ClassB.methodD(); } } public class Main{ public static void main(String args[]){ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ ɾɾɾ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ //͝ʹΐ͝ʹΐ } } public class ClassA{ void methodA(){…} void methodB(){…} } public class ClassB{ void methodC(){…} void methodD(){…} } .BJOKBWB $MBTT"KBWB $MBTT#KBWB .BJOKBWB
  8. ʮΫϥεʯ͸ʮొ৔ਓ෺ʯͷઃܭਤɻ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; } ଐੑ ػೳ
  9. ʮंʯͬͯʮ͜͏͍͏ଐੑͱػೳ͕͋Δ΂͖ͩΑͶʯ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; } ଐੑ ػೳ
  10. ʮंʯͬͯʮ͜͏͋Δ΂͖ʯͩΑͶʂ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; } ଐੑ ػೳ
  11. ͦͷʮ͜͏͋Δ΂͖ʯͱ͍͏࢓༷Λɺଐੑˠʮม਺ʯʹɺ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; } ଐੑ ػೳ
  12. ػೳˠʮϝιουʯʹରԠͤͯ͞ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; } ଐੑ ػೳ
  13. ʮΫϥεʯͱͯ͠ઃܭ͢ΔͷͰ͢ɻ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; } ଐੑ ػೳ
  14. ͖ͬ͞ͷྫʹ໭Γ·͠ΐ͏ɻ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  15. ͍·खݩʹ͸ɺंͱΨιϦϯελϯυͷʲઃܭਤʳ͕͋Γ·͢ɻ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  16. Ͱ΋ɺઃܭਤ͚͕ͩ͋ͬͯ΋ɺ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  17. ʮ࣮෺ʯ͕ͳ͍ͱɺͳΜʹ΋໘ന͘ͳ͍Ͱ͢Ͷɻ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  18. ͜͜ͰʮԾ૝ੈքʯͬͯ࿩ʹ໭Γ·͢ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  19. ʮԾ૝ੈքʹ͜ΕΒͷ࣮ମ͕͋ͬͯʯ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  20. ͍ͦͭΒ͕ಈ͖ճͬͯ΍ΓͱΓΛ͢Δʜ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  21. ͦΕ͕ʮΦϒδΣΫτࢦ޲ʯͷࢥ૝Ͱͨ͠ɻ $BSKBWB public class Car{ int num; double dist; String

    name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  22. ·ͬ͞ΒͳʮԾ૝ੈքʯʹʮ࣮ମʯΛੜΈग़͢ͷͰ͢ɻ .BJOKBWB public class Main{ public static void main(String[] args){

    Car c = new Car(); GasStand g = new GasStand(); } } ͍ͰΑं ͍ͰΑ ΨιϦϯελϯυʂ $BSD (BT4UBOEH NBJOϝιου
  23. ͜͏͍͏;͏ʹԾ૝ੈքʹੜ·ΕΔʮ࣮ମʯͷ͜ͱΛ .BJOKBWB public class Main{ public static void main(String[] args){

    Car c = new Car(); GasStand g = new GasStand(); } } ͍ͰΑं ͍ͰΑ ΨιϦϯελϯυʂ $BSD (BT4UBOEH NBJOϝιου
  24. ʮΠϯελϯεʯͱݺͼ·͢ɻ .BJOKBWB public class Main{ public static void main(String[] args){

    Car c = new Car(); GasStand g = new GasStand(); } } ͍ͰΑं ͍ͰΑ ΨιϦϯελϯυʂ $BSD (BT4UBOEH NBJOϝιου ˞ʮΦϒδΣΫτʯͱݺͿਓ΋͍·͢ɻ
  25. ΠϯελϯεΛಈ͔͠·͢ɻ .BJOKBWB public class Main{ public static void main(String[] args){

    … c.drive(); c.gas_Fill(g); } $BSD (BT4UBOEH NBJOϝιου ૸Εं H͔Βڅ༉ͤΑ ं
  26. ʮं͕ΨιϦϯΛೖΕʹߦ͘ʯϓϩάϥϜ͕Ͱ͖·ͨ͠ .BJOKBWB public class Main{ public static void main(String[] args){

    Car c = new Car(); GasStand g = new GasStand(); c.drive(); c.gas_Fill(g); } } $BSKBWB public class Car{ int num; double dist; String name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  27. ΦϒδΣΫτࢦ޲ͳιʔείʔυͰ͢ɻ .BJOKBWB public class Main{ public static void main(String[] args){

    Car c = new Car(); GasStand g = new GasStand(); c.drive(); c.gas_Fill(g); } } $BSKBWB public class Car{ int num; double dist; String name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} } (BT4UBOEKBWB public class GasStand{ double gasAmount; String shopName; }
  28. ͜ͷͭͷू߹ʹ͸͜Μͳؔ܎͕͋Γ·͢         ʜ

    ʜ ʮͬ͢ΆΓؚ·Ε͍ͯΔʯΠϝʔδɻ
  29. ͪͳΈʹɺ+BWBͰॻ͘ͱ͜͏ͳΓ·͢ 4QPSU$BSKBWB public class SportCar extends Car{ void superDrive(){…}; //ٸൃਐʢ௥Ճཁ݅ʣ

    } $BSKBWB public class Car{ int num; double dist; String name; void drive(){…} void stop(){…} void gas_fill(GasStand g){…} }