KotlinでAPIを型安全にした話

106e9af235dcfbc6251b38def24a0f8b?s=47 noripi
December 19, 2017

 KotlinでAPIを型安全にした話

2017.12.19 R.kt#2の発表で使用したスライドです。

106e9af235dcfbc6251b38def24a0f8b?s=128

noripi

December 19, 2017
Tweet

Transcript

  1. 2.

    ͍͋ͭࣗ͝͞ݾ঺հ  ɾ໊લ/PSJZVLJ*TIJEB  ɾαʔόαΠυʢ,PUMJO+BWB1)11ZUIPO ɾΤϯδχΞ!3FUUZ ɾJ04 4XJGU0CKFDUJWF$ ɾ"84΋ͦͦ͜͜৮Δ ɾ,PUMJOྺ೥ϲ݄͘Β͍

    ɾ,PUMJO͔Θ͍͍ ɾ࠷ۙ,PUMJO͗ͯ͢͠+BWBΛ๨Ε͖ͯͨ ɾ,PUMJO/BUJWFʹ΋ظ଴͍ͯ͠Δ IUUQTRJJUBDPNOPSJQJJUFNTFFDCEBDBGCE
  2. 17.

    Ҡߦͯ͠ؾ͍ͮͨ,PUMJOͷϝϦοτ   ɾσʔλϗϧμΫϥεͷఆٛ ɾฦΓ஋ͷܕΛ10+0 ී௨ͷ+BWBΦϒδΣΫτ Ͱࣄલʹఆٛ͢Δඞཁ͕͋Δ ɾ+BWBͩͱఆٛ͢Δͷ͕ͪΐͬͱΊΜͲ͍͘͞ public class

    GetRestaurantResponse { private long restaurantId; private String restaurantName; public long getRestaurantId() { return this.restaurantId; } public String getRestaurantName() { return this.restaurantName; } }
  3. 19.

    Ҡߦͯ͠ؾ͍ͮͨ,PUMJOͷϝϦοτ   ɾ$MBTT%FMFHBUJPO ɾجຊతͳܕΛ૊Έ߹ΘͤͯฦΓ஋Λ࡞Γ͍ͨέʔε͸ׂͱΑ͋͘Δ ɾ+BWBͩͱఆٛ͢Δͷ͕͍ͩͿΊΜͲ͍͘͞ public class GetReviewResponse implements

    IReview, IRestaurant, IUser { private IReview review; private IRestaurant restaurant; private IUser user; public long getReviewId() { return this.review.getReviewId(); } public String getUserName() { return this.user.getUserName(); } public String getRestaurantName() { return this.restaurant.getRestaurantName(); } ... }
  4. 20.

    Ҡߦͯ͠ؾ͍ͮͨ,PUMJOͷϝϦοτ   ɾ$MBTT%FMFHBUJPO ɾΠϯλϑΣʔεͷ࣮૷ΛଞͷΫϥεʹҠৡͰ͖Δ ɾQSPQFSUZΛࡉ͔͘JOUFSGBDFԽ͓͚ͯ͠͹ɺฦΓ஋ΫϥεΛࡉ͔͘ఆٛՄೳʹ data class GetReviewResponse( private

    val review: IReview, private val restaurant: IRestaurant, private val user: IUser ) : IReview by review, IRestaurant by restaurant, IUser by user { // ෳ਺ͷinterfaceͰఆ͕͔ٛͿͬͯΔͱ͖͚ͩ໌ࣔతʹࢦఆ override val userId: Int = this.user.userId }