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

Androidアプリを作る 第3回

nonylene
November 06, 2016

Androidアプリを作る 第3回

nonylene

November 06, 2016
Tweet

More Decks by nonylene

Other Decks in Technology

Transcript

  1. .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 + "߸"; } }
  2. $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 + "݄߸"; } }
  3. .BHB[JOFܧঝ * CodeMagazine.java class ComicMagazine extends Magazine { public ComicMagazine(String

    title, String company, int number) { super(title, "ອըࡶࢽ", company, number); } } Magazine Λܧঝ
  4. .BHB[JOFܧঝ * CodeMagazine.java class ComicMagazine extends Magazine { public ComicMagazine(String

    title, String company, int number) { super(title, "ອըࡶࢽ", company, number); } } Magazine ʹఆٛ͞ΕͨίϯετϥΫλΛݺͿ ※ genre Λৗʹ “ອըࡶࢽ” ͱ͍ͯ͠Δ
  5. * 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 ม਺Λఆٛ
  6. * 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 ΫϥεͷίϯετϥΫλΛݺͿ
  7. * 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 ͸ͳ͍
  8. * 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() ͸ͳ͍
  9. w લ४උ w MangaTimeKiraraMAX͔Β
 title / number / coverTitle ʹ


    ΞΫηεͰ͖ΔΑ͏ʹ͢Δ .BOHB5JNF,JSBSB."9࣮૷
  10. ΞΫηεम০ࢠมߋ * Magazine.java class Magazine { protected String title; private

    String genre; private String company; protected int number; public Magazine(… }
  11. .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 ͢Δ
  12. 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·Μ͕λΠϜ͖ΒΒͷυΩυΩʢུʣ
  13. ྫ 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);
  14. * 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 म০ࢠΛ͚ͭΔ
  15. * 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ϝιουΛ௥Ճʢ࣮૷͸ॻ͔ͳ͍ʣ
  16. * 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 "εςϥͷ·΄͏"; } }
  17. "CTUSBDUΫϥεΛҾ਺ʹ public void printAnimeTitle(BaseMangaTimeKirara magazine) { System.out.println( magazine.getAnimeTitle() ); }

    // BaseMangaTimeKirara ͸΋͏ΦϒδΣΫτΛ௚઀࡞੒Ͱ͖ͳ͍ MangaTimeKiraraMAX max = new MangaTimeKiraraMAX("͖Μ͍ΖϞβΠΫ" , 1); printAnimeTitle(max); ௨ৗͷΫϥεͱಉ͡Α͏ʹϝιουΛݺ΂Δ
  18. *OUFSGBDFͱ
 "CTUSBDU$MBTT w "CTUSBDU$MBTT͸਌ࢠؔ܎ w " ࢠ JT# ਌ 


    w *OUFSGBDF͸ೳྗతͳײ͡ w " Ϋϥε DBO# ΠϯλʔϑΣʔε
  19. 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 ͢Δ
  20. 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 ϝιουΛ࣮૷͢Δ
  21. class Magazine implements FileExportable, Hoge, Piyo { } w *OUFSGBDF͸ෳ਺࣮૷Մೳ

    w “,”Ͱ۠੾ͬͯॻ͘ w ͦΕͧΕʹఆٛ͞ΕͨϝιουΛ࣮૷͢Δ
  22. public void exportFile( FileExportable exportable ) { exportable.export(); } MangaTimeKiraraMAX

    max = new MangaTimeKiraraMAX("͖Μ͍ΖϞβΠΫ" , 1); exportFile(max); Ҿ਺ͷܕʹΠϯλʔϑΣʔεΛࢦఆ͢Δ
  23. public void exportFile( FileExportable exportable ) { exportable.export(); } MangaTimeKiraraMAX

    max = new MangaTimeKiraraMAX("͖Μ͍ΖϞβΠΫ" , 1); exportFile(max); FileExportable Λ࣮૷͍ͯ͠ΔΫϥεͰݺͼग़͠
  24. ҉໧తͳܕม׵
 ʢϓϦϛςΟϒܕʣ ਫ਼౓ߴ͍ ਫ਼౓௿͍ long int long longValue = 2;

    ৄࡉ: http://www.atmarkit.co.jp/ait/articles/0803/18/news149.html
  25. ComicMagazine Magazine Magazine magazine = new ComicMagazine(…); ComicMagazine comicMagazine =

    (ComicMagazine) magazine; ਌ ࢠ ໌ࣔతͳܕม׵ʢΩϟετʣ
  26. FileExportable exportable = new Magazine(…); Magazine magazine = (Magazine) magazine;

    ΠϯλʔϑΣʔε ࣮૷Ϋϥε FileExportable Magazine ໌ࣔతͳܕม׵ʢΩϟετʣ
  27. ໌ࣔతͳܕม׵
 ʢΩϟετ ϓϦϛςΟϒܕʣ ਫ਼౓ߴ͍ ਫ਼౓௿͍ long int long longValue =

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