Androidアプリを作る 第3回

9b6ca173883528d3bd047ca8f20b0bce?s=47 nonylene
November 06, 2016

Androidアプリを作る 第3回

9b6ca173883528d3bd047ca8f20b0bce?s=128

nonylene

November 06, 2016
Tweet

Transcript

  1. 11.
  2. 21.

    .BHB[JOFΫϥε࣮૷ * Magazine.java class Magazine { private String title; private

    String genre; private String company; private int number; public Magazine(String title, String genre, String company,
 int number) { this.title = title; this.genre = genre; this.company = company; this.number = number; } public String getInfoText() { return company + " ͷ " + title + number + "߸"; } }
  3. 23.

    $PNJD.BHB[JOF࣮૷ * ComicMagazine.java class ComicMagazine { private String title; private

    String genre = "ອըࡶࢽ"; private String company; private int number; public ComicMagazine(String title, String company, int number) { this.title = title; this.company = company; this.number = number; } public String getInfoText() { return company + "ͷ" + title + number + "݄߸"; } }
  4. 28.

    .BHB[JOFܧঝ * CodeMagazine.java class ComicMagazine extends Magazine { public ComicMagazine(String

    title, String company, int number) { super(title, "ອըࡶࢽ", company, number); } } Magazine Λܧঝ
  5. 29.

    .BHB[JOFܧঝ * CodeMagazine.java class ComicMagazine extends Magazine { public ComicMagazine(String

    title, String company, int number) { super(title, "ອըࡶࢽ", company, number); } } Magazine ʹఆٛ͞ΕͨίϯετϥΫλΛݺͿ ※ genre Λৗʹ “ອըࡶࢽ” ͱ͍ͯ͠Δ
  6. 32.

    * BaseMangaTimeKirara.java class BaseMangaTimeKirara extends ComicMagazine { private String coverTitle;

    public BaseMangaTimeKirara(String title, String coverTitle, int number) { super(title, "๕จࣾ", number); this.coverTitle = coverTitle; } public String getCoverTitle() { return coverTitle; } } #BTF.BOHB5JNF,JSBSB࣮૷ coverTitle ม਺Λఆٛ
  7. 33.

    * BaseMangaTimeKirara.java class BaseMangaTimeKirara extends ComicMagazine { private String coverTitle;

    public BaseMangaTimeKirara(String title, String coverTitle, int number) { super(title, "๕จࣾ", number); this.coverTitle = coverTitle; } public String getCoverTitle() { return coverTitle; } } #BTF.BOHB5JNF,JSBSB࣮૷ ComicMagazine ΫϥεͷίϯετϥΫλΛݺͿ
  8. 34.

    * BaseMangaTimeKirara.java class BaseMangaTimeKirara extends ComicMagazine { private String coverTitle;

    public BaseMangaTimeKirara(String title, String coverTitle, int number) { super(title, "๕จࣾ", number); this.coverTitle = coverTitle; } public String getCoverTitle() { return coverTitle; } } #BTF.BOHB5JNF,JSBSB࣮૷ coverTitle ʹ୅ೖ͢Δ ※ ComicMagazine ʹ͸ coverTitle ͸ͳ͍
  9. 35.

    * BaseMangaTimeKirara.java class BaseMangaTimeKirara extends ComicMagazine { private String coverTitle;

    public BaseMangaTimeKirara(String title, String coverTitle, int number) { super(title, "๕จࣾ", number); this.coverTitle = coverTitle; } public String getCoverTitle() { return coverTitle; } } #BTF.BOHB5JNF,JSBSB࣮૷ getCoverTitle() ϝιουΛఆٛ ※ ComicMagazine ʹ͸ getCoverTitle() ͸ͳ͍
  10. 39.

    w લ४උ w MangaTimeKiraraMAX͔Β
 title / number / coverTitle ʹ


    ΞΫηεͰ͖ΔΑ͏ʹ͢Δ .BOHB5JNF,JSBSB."9࣮૷
  11. 41.

    ΞΫηεम০ࢠมߋ * Magazine.java class Magazine { protected String title; private

    String genre; private String company; protected int number; public Magazine(… }
  12. 44.

    .BOHB5JNF,JSBSB."9࣮૷ * MangaTimeKiraraMAX.java class MangaTimeKiraraMAX extends BaseMangaTimeKirara { public MangaTimeKiraraMAX(String

    coverTitle, int number) { super("·Μ͕λΠϜ͖ΒΒMAX", coverTitle, number); } @Override public String getInfoText() { return "·Μ͕λΠϜ͖ΒΒͷυΩυΩϏδϡΞϧίϛοΫε!ࠓ݄ͷ" + title + number + "݄߸ͷදࢴ͸" + coverTitle + "!"; } } getInfoText() Λ Override ͢Δ
  13. 45.

    BaseMangaTimeKirara kirara = new BaseMangaTimeKirara( "·Μ͕λΠϜ͖ΒΒMAX", "͖Μ͍ΖϞβΠΫ" , 1); String

    text = kirara.getInfoText(); MangaTimeKiraraMAX max = new MangaTimeKiraraMAX( "͖Μ͍ΖϞβΠΫ" , 1); String maxText = max.getInfoText(); .BOHB5JNF,JSBSB."9׬੒ UFYU๕จࣾͷ·Μ͕λΠϜ͖ΒΒ."9݄߸ NBY5FYU·Μ͕λΠϜ͖ΒΒͷυΩυΩʢུʣ
  14. 47.

    ྫ public void printInfo(Magazine magazine) { System.out.println(magazine.getInfoText()); } public void

    printCoverTitle(BaseMangaTimeKirara magazine) { System.out.println(magazine.getCoverTitle()); } MangaTimeKiraraMAX max = new MangaTimeKiraraMAX("͖Μ͍ΖϞβΠΫ" , 1); printInfo(max); printCoverTitle(max);
  15. 52.

    * BaseMangaTimeKirara.java abstract class BaseMangaTimeKirara extends ComicMagazine { protected String

    coverTitle; public BaseMangaTimeKirara(String title, String coverTitle, int number) { super(title, , number); this.coverTitle = coverTitle; } public String getCoverTitle() { return coverTitle; } public abstract String getAnimeTitle(); } abstract म০ࢠΛ͚ͭΔ
  16. 53.

    * BaseMangaTimeKirara.java abstract class BaseMangaTimeKirara extends ComicMagazine { protected String

    coverTitle; public BaseMangaTimeKirara(String title, String coverTitle, int number) { super(title, , number); this.coverTitle = coverTitle; } public String getCoverTitle() { return coverTitle; } public abstract String getAnimeTitle(); } BCTUSBDUϝιουΛ௥Ճʢ࣮૷͸ॻ͔ͳ͍ʣ
  17. 55.

    * MangaTimeKiraraMAX.java class MangaTimeKiraraMAX extends BaseMangaTimeKirara { public MangaTimeKiraraMAX(String coverTitle,

    int number) { super("·Μ͕λΠϜ͖ΒΒMAX", coverTitle, number); } @Override public String getInfoText() { return “·Μ͕λΠϜ͖ΒΒ…" + …(ུ); } @Override public String getAnimeTitle() { return "εςϥͷ·΄͏"; } }
  18. 56.

    "CTUSBDUΫϥεΛҾ਺ʹ public void printAnimeTitle(BaseMangaTimeKirara magazine) { System.out.println( magazine.getAnimeTitle() ); }

    // BaseMangaTimeKirara ͸΋͏ΦϒδΣΫτΛ௚઀࡞੒Ͱ͖ͳ͍ MangaTimeKiraraMAX max = new MangaTimeKiraraMAX("͖Μ͍ΖϞβΠΫ" , 1); printAnimeTitle(max); ௨ৗͷΫϥεͱಉ͡Α͏ʹϝιουΛݺ΂Δ
  19. 57.
  20. 59.

    *OUFSGBDFͱ
 "CTUSBDU$MBTT w "CTUSBDU$MBTT͸਌ࢠؔ܎ w " ࢠ JT# ਌ 


    w *OUFSGBDF͸ೳྗతͳײ͡ w " Ϋϥε DBO# ΠϯλʔϑΣʔε
  21. 65.

    class Magazine implements FileExportable { protected String tit… public Magazine(String

    titl…) { this.title = ti…; } public String getInfoText() { return co… } @Override public void export() { // export ॲཧΛॻ͘ } } FileExportable Λ implement ͢Δ
  22. 66.

    class Magazine implements FileExportable { protected String tit… public Magazine(String

    titl…) { this.title = ti…; } public String getInfoText() { return co… } @Override public void export() { // export ॲཧΛॻ͘ } } export ϝιουΛ࣮૷͢Δ
  23. 67.

    class Magazine implements FileExportable, Hoge, Piyo { } w *OUFSGBDF͸ෳ਺࣮૷Մೳ

    w “,”Ͱ۠੾ͬͯॻ͘ w ͦΕͧΕʹఆٛ͞ΕͨϝιουΛ࣮૷͢Δ
  24. 69.

    public void exportFile( FileExportable exportable ) { exportable.export(); } MangaTimeKiraraMAX

    max = new MangaTimeKiraraMAX("͖Μ͍ΖϞβΠΫ" , 1); exportFile(max); Ҿ਺ͷܕʹΠϯλʔϑΣʔεΛࢦఆ͢Δ
  25. 70.

    public void exportFile( FileExportable exportable ) { exportable.export(); } MangaTimeKiraraMAX

    max = new MangaTimeKiraraMAX("͖Μ͍ΖϞβΠΫ" , 1); exportFile(max); FileExportable Λ࣮૷͍ͯ͠ΔΫϥεͰݺͼग़͠
  26. 80.

    ҉໧తͳܕม׵
 ʢϓϦϛςΟϒܕʣ ਫ਼౓ߴ͍ ਫ਼౓௿͍ long int long longValue = 2;

    ৄࡉ: http://www.atmarkit.co.jp/ait/articles/0803/18/news149.html
  27. 81.

    ComicMagazine Magazine Magazine magazine = new ComicMagazine(…); ComicMagazine comicMagazine =

    (ComicMagazine) magazine; ਌ ࢠ ໌ࣔతͳܕม׵ʢΩϟετʣ
  28. 82.

    FileExportable exportable = new Magazine(…); Magazine magazine = (Magazine) magazine;

    ΠϯλʔϑΣʔε ࣮૷Ϋϥε FileExportable Magazine ໌ࣔతͳܕม׵ʢΩϟετʣ
  29. 83.

    ໌ࣔతͳܕม׵
 ʢΩϟετ ϓϦϛςΟϒܕʣ ਫ਼౓ߴ͍ ਫ਼౓௿͍ long int long longValue =

    2; int intValue = (int) longValue; ৄࡉ: http://www.atmarkit.co.jp/ait/articles/0803/18/news149.html