Fat ViewControllerを倒せ!
〜Cocoa MVC への道のり〜 / No More Fat ViewController! ~The path to Cocoa MVC~

Fat ViewControllerを倒せ!
〜Cocoa MVC への道のり〜 / No More Fat ViewController! ~The path to Cocoa MVC~

Af64bc38c0ffcfcabdf430759ee491ce?s=128

Elvis Shi

May 30, 2020
Tweet

Transcript

  1. 'BU7JFX$POUSPMMFSΛ౗ͤʂ ʙ$PDPB.7$΁ͷಓͷΓʙ f o r  4X J G U

     ;P PN J O      Ԇ ௕ ઓ
  2. } var employedBy = "YUMEMI Inc." var job = "iOS

    Tech Lead" var favoriteLanguage = "Swift" var twitter = "@lovee" var qiita = "lovee" var github = "el-hoshino" var additionalInfo = """ Twitter෮׆ͨ͠ʂ """ final class Me: Developable, Talkable {
  3. IUUQTHJUIVCDPNSFGBDUPSJOHDIBMMFOHFSFWFSTJJPT

  4. طଘϓϩδΣΫτͷ໰୊఺ w ϩδοΫ͕༷ʑͳ৔ॴʹࠞࡏ͍ͯ͠Δ w ϦηοτϩδοΫ͕BoardViewʹ w ਐߦϩδοΫ͕ViewControllerʹ w ൫αΠζϩδοΫ͕BoardViewʹ w

    ΞχϝʔγϣϯϩδοΫ͕ViewControllerʹ
  5. $PDPB.7$ͷߏ੒ 7JFX$POUSPMMFS .PEFM 7JFX ߦಈ ૢ࡞ ௨஌ ߋ৽

  6. $PDPB.7$ͷߏ੒ w .PEFMɿήʔϜϩδοΫͷॲཧ w 7JFXɿը໘ඳըͱɺϢʔβΞΫγϣϯͷड෇ w 7JFX$POUSPMMFSɿ7JFXͱ.PEFMͷՍ͚ڮ

  7. $PDPB.7$ͷߏ੒ w (BNF&OHJOFɿήʔϜϩδοΫͷॲཧ w #PBSE7JFXɿը໘ඳըͱɺϢʔβΞΫγϣϯͷड෇ w 7JFX$POUSPMMFSɿ#PBSE7JFXͱ(BNF&OHJOFͷ Ս͚ڮ

  8. मਖ਼ํ޲ʢίϯϙʔωϯτʣ w (BNF&OHJOFʹશͯͷήʔϜϩδοΫΛू໿ w 7JFX$POUSPMMFSͱ#PBSE7JFXͷήʔϜϩδοΫ Λશͯ(BNF&OHJOFʹҠಈ w #PBSE7JFXʹඳըॲཧͷΈΛ࢒͢ w ήʔϜϧʔϧ౳ʹґଘͤͣɺݴΘΕͨ௨Γʹ͢Δ

    ͚ͩͷඳըϩδοΫ w طଘͷॲཧίʔυࣗମ͸࠷খݶͷमਖ਼Ͱ
  9. मਖ਼ํ޲ʢσʔλϑϩʔʣ w ॲཧͷྲྀΕΛҰຊಓԽ w BoardView͕ϢʔβΞΫγϣϯΛड͚ͨΒ@IBAction΋ ͘͠͸delegate௨ͯ͠ViewControllerʹ఻ୡ w ViewController͕΋ΒͬͨϢʔβΞΫγϣϯΛݩʹ GameEngineΛૢ࡞ w

    GameEngine͕ಠࣗઐ༻εϨουͰૢ࡞Λॲཧ͠ɺͦͷ݁Ռ ΛAnyPublisherͰViewControllerʹ௨஌ w ViewController͕΋Βͬͨ݁ՌΛݩʹϝΠϯεϨουͰ BoardViewΛߋ৽ w BoardView͕ͦͷ݁Ռͷ௨Γʹඳը
  10. $PDPB.7$ͷߏ੒ 7JFX$POUSPMMFS .PEFM 7JFX ૢ࡞ ௨஌ ߋ৽ ߦಈ

  11. $PDPB.7$ͷߏ੒ 7JFX$POUSPMMFS (BNF&OHJOF #PBSE7JFX ૢ࡞ ௨஌ ߋ৽ ߦಈ

  12. $PDPB.7$ͷߏ੒ 7JFX$POUSPMMFS (BNF&OHJOF #PBSE7JFX reset() setPlayer(_:for:) getPlayer(for:)-> placeDisk(at:) nextMove() currentBoard{get}

    saveGame() loadGame() $isThinking $changedDisks $currentTurn $currentCount boardSize{set} changeDisks(at:to:) reset(with:) @pressReset(_:) @changePlayerControl(_:) .didSelectCell(at:) $AnyPublisherͱͯ͠ฦ͞ΕΔ @@IBActionΛ௨ͯ͠ݺ͹ΕΔ .delegateΛ௨ͯ͠ݺ͹ΕΔ
  13. %&.0

  14. ൓ল఺ w ෦඼࡞ͬͯॲཧΛҠಈ͢Δલʹɺ΋͏গ͠ϝιουΛ ࡉ͔͘੾Γग़͢΂͖ͩͬͨ w ॲཧͷҠಈͱϝιουͷ੾Γग़͠ͱςετͷ࣮૷ͷ ಉ࣌ฒߦ͕ڧ͍ΒΕͯେมͩͬͨ w ͞Βʹͦͷ͍ͤͰ్த͔Βςετॻ͘ͷ΋ఘΊͨ

  15. ͦͷଞ w $PDPB.7$ͷߏ੒ͷઆ໌͚ͩͳͷͰɺGameEngine ͕·ͩগʑ'BU w GameEngineΛ७ਮؔ਺Խͯ͠ɺ֤छঢ়ଶΛ͞Βʹ GameStoreͱ͔ʹ੾Γग़ͤ͹ߋʹ͖Ε͍ʹͳΔ w ΍ͬͺ6*,JUʹͱͬͯ$PDPB.7$͸ָʂ w

    protocolͰ@Published<Value>ͱ͔ΛએݴͰ͖Δ Α͏ʹͯ͠΄͍͠ w ࠓ͸AnyPublisher<Value, Never> { get }Ͱ ఆٛ͢Δ͔͠ͳ͍ͷ͕ඍົʹਏ͍