<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Piyapan Duwao on Medium]]></title>
        <description><![CDATA[Stories by Piyapan Duwao on Medium]]></description>
        <link>https://medium.com/@piyapan.dev?source=rss-2cda78cc2c72------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yn5dn4gOJZ9zTTD8yJ2VQQ.jpeg</url>
            <title>Stories by Piyapan Duwao on Medium</title>
            <link>https://medium.com/@piyapan.dev?source=rss-2cda78cc2c72------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 02:48:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@piyapan.dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[เลิกปวดหัวกับ Test! ปรับโค้ด ให้ยืดหยุ่นด้วย Loose Coupling และ DI]]></title>
            <link>https://medium.com/myorder/%E0%B9%80%E0%B8%A5%E0%B8%B4%E0%B8%81%E0%B8%9B%E0%B8%A7%E0%B8%94%E0%B8%AB%E0%B8%B1%E0%B8%A7%E0%B8%81%E0%B8%B1%E0%B8%9A-test-%E0%B8%9B%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B9%82%E0%B8%84%E0%B9%89%E0%B8%94-%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B8%A2%E0%B8%B7%E0%B8%94%E0%B8%AB%E0%B8%A2%E0%B8%B8%E0%B9%88%E0%B8%99%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-loose-coupling-%E0%B9%81%E0%B8%A5%E0%B8%B0-di-bde8e72c5988?source=rss-2cda78cc2c72------2</link>
            <guid isPermaLink="false">https://medium.com/p/bde8e72c5988</guid>
            <category><![CDATA[testable-code]]></category>
            <category><![CDATA[loosecoupling]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Piyapan Duwao]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 05:00:09 GMT</pubDate>
            <atom:updated>2026-02-17T05:00:09.404Z</atom:updated>
            <content:encoded><![CDATA[<p><em>คุณเคยเจอปัญหาตอนเขียน test ไหมว่า “ทำไมถึง mock Something ไม่ได้” หรือ “ต้องเชื่อมต่อ Something จริงทุกครั้งที่รัน test เหรอ?” หรือ “ต้อง mock Something ยาว 8 เมตรเลยหรอ?” บทความนี้จะแสดงให้เห็นว่า Loose Coupling และ Dependency Injection แก้ปัญหาเหล่านี้ได้อย่างไร ผ่านตัวอย่างโค้ดจริงที่ใช้งานได้</em></p><h4>ก่อนอื่น มารู้จัก Tight Coupling และ Loose Coupling กันก่อน</h4><h4>Tight Coupling (ผูกติดกันแน่น)</h4><p>คือการที่ Code สองส่วน <strong>“รู้จักกันและพึ่งพากันมากเกินไป”</strong> เหมือนคนสองคนที่ตัวติดกัน ถ้าคนหนึ่งขยับ อีกคนต้องขยับตาม ถ้าคนหนึ่งล้ม อีกคนก็ล้มไปด้วย</p><ul><li><strong>ตัวอย่าง:</strong> Class A สร้าง (new) Class B ไว้ข้างในตัวเองเลย</li><li><strong>ผลเสีย:</strong> ถ้าอยากเปลี่ยนไปใช้ Class C แทน Class B คุณต้องไล่แก้ Code ใน Class A ทั้งหมด และเวลาเขียน Test คุณแยกมันออกจากกันไม่ได้เลย</li></ul><h4>Loose Coupling (ผูกกันหลวมๆ)</h4><p>คือการที่ Code สองส่วน <strong>“คุยกันผ่านตัวกลาง (Interface)”</strong> โดยไม่จำเป็นต้องรู้จักตัวตนจริงๆ ของกันและกัน เหมือนคนใช้ปลั๊กไฟครับ ปลั๊กไฟ (Interface) ไม่สนว่าคุณจะเอาพัดลมหรือทีวีมาเสียบ ขอแค่ขาปลั๊กตรงกันก็พอ</p><ul><li><strong>ตัวอย่าง:</strong> Class A บอกแค่ว่า “ฉันต้องการอะไรก็ได้ที่ทำงานตามเงื่อนไขนี้” แล้วเราส่ง (Inject) ของชิ้นนั้นเข้าไปให้จากข้างนอก</li><li><strong>ผลดี:</strong> คุณสามารถเปลี่ยนของได้ตลอดเวลา (เช่น สลับจาก API จริง เป็น API ปลอมเพื่อ Test) โดยไม่ต้องแก้ Code หลักแม้แต่บรรทัดเดียว</li></ul><h3>ตัวอย่าง: ต่อ Google Auth API ใน Node</h3><p>สมมติว่าเราต้องเขียนระบบที่ต่อกับ Google Android Publisher API get ข้อมูล โดยต้องใช้ Google Auth เพื่อขอ access token</p><blockquote><strong><em>🎯 สิ่งที่ต้องทำ:</em></strong></blockquote><blockquote><em>1. สร้าง GoogleAuth instance ด้วย credentials<br>2. ขอ access token จาก Google<br>3. ใช้ token ในการเรียก Android Publisher API<br>4. </em><strong><em>และที่สำคัญ: ต้องเขียน test ได้!</em></strong></blockquote><h4>❌ ปัญหา: Tight Coupling</h4><p>หลายคนอาจเขียนโค้ดแบบนี้ โดยสร้าง GoogleAuth ตรงๆ ภายใน class:</p><pre>import { google, androidpublisher_v3 } from &quot;googleapis&quot;;<br>import type { GoogleAuth } from &quot;google-auth-library&quot;;<br>import { config } from &quot;../config/config&quot;;<br><br>// ❌ ปัญหา: GoogleAuthService สร้าง GoogleAuth เองภายใน class<br>class GoogleApiService {<br>    private googlePlayClient: GoogleAuth;<br>    private androidPublisher: androidpublisher_v3.Androidpublisher;<br><br>    constructor() {<br>        this.googlePlayClient = new google.auth.GoogleAuth({<br>            keyFile: config.GOOGLE_APPLICATION_CREDENTIALS,<br>            scopes: [&quot;https://www.googleapis.com/auth/androidpublisher&quot;],<br>        });<br>        this.androidPublisher = google.androidpublisher({<br>            version: &quot;v3&quot;,<br>            auth: this.googlePlayClient,<br>        });<br>    }<br><br>    public async verifyData() {<br>        try {<br>            const res = await this.androidPublisher.purchases.products.get();<br>            return res.data;<br>        } catch (error) {<br>            return error;<br>        }<br>    }<br>}<br><br>export default GoogleApiService;</pre><p><strong>⚠️ ปัญหาที่เกิดขึ้น:</strong><br>• GoogleAuth ถูกสร้างภายใน class ตั้งแต่แรก<br>• ไม่สามารถ mock หรือเปลี่ยนได้<br>• ต้องเชื่อมต่อ Google จริงทุกครั้งที่รัน test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fc5-i5EuXMU6iI6Z5GpZaA.png" /></figure><h4>✅ วิธีแก้: Loose Coupling + Dependency Injection</h4><p>เราแก้ไขโดย ส่ง GoogleAuth เข้ามาจากข้างนอก ด้วย Interface แทนที่จะสร้างเอง ภายใน:</p><pre>import { IAndroidPublisher } from &quot;../interfaces/android-publisher.interface&quot;;<br><br>class GoogleApiService {<br>    private androidPublisher: IAndroidPublisher;<br><br>    constructor(androidPublisher: IAndroidPublisher) {<br>        this.androidPublisher = androidPublisher;<br>    }<br><br>    public async verifyData(){<br>        try {<br>            const res = await this.androidPublisher.purchases.products.get();<br>            return res.data;<br>        } catch (error) {<br>            return error;<br>        }<br>    }<br>}<br><br>export default GoogleApiService;</pre><p>โดย GoogleAuth จะถูกเรียกใช้งานตั้งแต่ main และถูกส่งเข้ามา ตามนี้:</p><pre>async function createAndroidPublisher() {<br>    try {<br>        const googleAuth = new google.auth.GoogleAuth({<br>            keyFile: config.GOOGLE_APPLICATION_CREDENTIALS,<br>            scopes: [&quot;https://www.googleapis.com/auth/androidpublisher&quot;],<br>        });<br>        await googleAuth.getAccessToken();<br>        return google.androidpublisher({<br>            version: &quot;v3&quot;,<br>            auth: googleAuth,<br>        });<br>    } catch (error) {<br>        throw error;<br>    }<br>}<br><br>async function bootserver() {<br>    try {<br>        const androidPublisher = await createAndroidPublisher();<br>        new GoogleApiService(androidPublisher);<br>    } catch (error) {<br>        process.exit(1);<br>    }<br>}<br><br>bootserver();</pre><p>👍 <strong>ข้อดี:</strong><br>• ควบคุมได้ว่าจะส่ง GoogleAuth แบบไหนเข้าไป<br>• เวลา test สามารถส่ง mock object เข้าไปได้<br>• Test รันเร็ว ไม่ต้องเชื่อมต่อ Google จริง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LzhVZFOYMJz89zH2eifBWw.png" /></figure><h4>🎉 ผลลัพธ์: การทำ Mock Test ที่ง่ายดาย</h4><p>นี่คือผลลัพธ์ที่เราต้องการครับ ในการเขียน Test เราไม่จำเป็นต้องใช้ GoogleTokenProvider ตัวจริงเลย เราสามารถสร้าง &quot;Mock&quot; ง่ายๆ ที่ implement interface เดียวกัน แล้วส่งเข้าไปแทน</p><pre>import { IAndroidPublisher } from &quot;../interfaces/android-publisher.interface&quot;;<br>import GoogleApiService from &quot;./google-api.service&quot;;<br><br>describe(&quot;GoogleApiService&quot;, () =&gt; {<br>  let googleApiService: GoogleApiService;<br>  let mockProductsGet: jest.Mock;<br>  let mockAndroidPublisher: IAndroidPublisher;<br><br>  beforeEach(() =&gt; {<br>    jest.clearAllMocks();<br>    mockProductsGet = jest.fn();<br>    mockAndroidPublisher = {<br>      purchases: {<br>        products: {<br>          get: mockProductsGet,<br>        },<br>      },<br>    };<br>    googleApiService = new GoogleApiService(mockAndroidPublisher);<br>  });</pre><h3>💡 สรุป</h3><p><strong>Loose Coupling</strong> คือการออกแบบโค้ดให้แต่ละส่วนไม่ผูกติดกันแน่นเกินไป ทำให้แต่ละส่วนสามารถทำงานได้อิสระและเปลี่ยนแปลงได้ง่าย</p><p><strong>Dependency Injection</strong> คือเทคนิคในการส่ง dependencies ที่ class ต้องการเข้ามาจากข้างนอก (ผ่าน constructor) แทนที่จะสร้างเองภายใน class</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bde8e72c5988" width="1" height="1" alt=""><hr><p><a href="https://medium.com/myorder/%E0%B9%80%E0%B8%A5%E0%B8%B4%E0%B8%81%E0%B8%9B%E0%B8%A7%E0%B8%94%E0%B8%AB%E0%B8%B1%E0%B8%A7%E0%B8%81%E0%B8%B1%E0%B8%9A-test-%E0%B8%9B%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B9%82%E0%B8%84%E0%B9%89%E0%B8%94-%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B8%A2%E0%B8%B7%E0%B8%94%E0%B8%AB%E0%B8%A2%E0%B8%B8%E0%B9%88%E0%B8%99%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-loose-coupling-%E0%B9%81%E0%B8%A5%E0%B8%B0-di-bde8e72c5988">เลิกปวดหัวกับ Test! ปรับโค้ด ให้ยืดหยุ่นด้วย Loose Coupling และ DI</a> was originally published in <a href="https://medium.com/myorder">myorder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build Mobile Application ด้วย Expo Application Services (EAS)]]></title>
            <link>https://medium.com/foxbith/build-mobile-application-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-expo-application-services-eas-d41a20c7f7d5?source=rss-2cda78cc2c72------2</link>
            <guid isPermaLink="false">https://medium.com/p/d41a20c7f7d5</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[expo-react-native]]></category>
            <dc:creator><![CDATA[Piyapan Duwao]]></dc:creator>
            <pubDate>Thu, 23 Dec 2021 04:23:58 GMT</pubDate>
            <atom:updated>2021-12-23T04:23:58.572Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build and Submit ด้วย Expo Application Services (EAS)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*88Rrt6GTP33zJCNH" /></figure><p>ก่อนที่จะพาทุกคนไปรู้จักกับ (EAS) อันดับแรกจะมาขออธิบายว่า ทำไมเราถึงมาใช้เจ้า (EAS) ตัวนี้กันก่อน</p><p>(EAS) คือ Service ที่จะช่วยเราในการพัฒนา Mobile Application Cross-Platform ของทาง Expo ซึ่ง Expo ก็เป็น SDK ชุดหนึ่งที่เข้ามาช่วยในการพัฒนา Application Cross-Platform ด้วย React Native</p><h3>React Native กับ Expo มันคืออะไรหรอ?</h3><p>สำหรับบางคนที่เข้ามาอ่านจะยังไม่รู้จัก เจ้า 2 ตัวนี้ งั้นจะขออธิบายสั้นๆพอให้เข้าใจเบื้องต้นก่อนไปทำความรู้จักกับ (EAS)</p><h4>React Native คือ</h4><p>เป็นเครื่องมือในการสร้าง Mobile Application บนระบบ Android และ iOS แบบ Cross-Platform โดยใช้ ภาษา JavaScript เป็นหลักในการเขียน</p><h4>Expo คือ</h4><p>เป็น SDK ที่พัฒนาเข้ามาช่วยให้การพัฒนา Mobile Application ของ React Native ให้มีความสะดวกสบายง่ายขึ้นนั้นเอง โดยไม่ต้องเข้ามาจัดการเขียน Native Module และมี Expo CLI ช่วยในการดู log การทำงานต่างๆ และการทดสอบ Mobile Application ผ่าน Device จริงทั้ง Android และ iOS แบบไม่ต้องเสียบสายเชื่อมต่อ 👍</p><h4>แต่…</h4><p>เวลาเราพัฒนาตัว ​Mobile Application เสร็จแล้วนั้น เราอยากได้ตัว Application ที่เราเขียนมาติดตั้งลงบน มือถือของเราเพื่อใช้งานจริง การที่เราใช้ React Native หรือ Expo จะทำได้ยุ่งยากมากกว่าจะได้ Application มาติดตั้งลงบน มือถือ ของเรา เช่น React Native ต้องเสียบสาย มือถือ เข้ากับคอมที่เราพัฒนา Moblie Application ต้อง Config Native ของแต่ละ Platform ทั้ง Android และ IOS ซึ่งดูแล้วยุ่งยากต้องทำหลายขั้นตอนกว่าจะได้ Application มาติดตั้งลงบน มือถือของเรา หรือ ถ้าเป็น Expo เราต้องทำการ Start Project “<em>expo start” </em>ค้างไว้แล้วจะได้ qr code มา แล้วให้ผู้ทดสอบลง Application expoGo และ Scan Qr code เพื่อทดสอบ Application ของเราซึ่งมันยุ่งยาก</p><h4>มาทำความรู้จักเจ้า (EAS) กัน</h4><p>Expo Application Services (EAS) เป็น New Cloud Services ใหม่จากทาง Expo ซึ่งถูกพัฒนามาช่วยเหลือนักพัฒนา Mobile Application ด้วย Expo เพราะเวลาที่เรา พัฒนา Mobile Application ด้วย Expo เราพัฒนาผ่าน Application ExpoGo ที่เป็น Application ช่วยให้เราสะดวกสบายในการ เขียนพัฒนาและทดสอบ ตัว Application ที่เราสร้างขึ้น แค่ Scan QR Code ผ่าน Application ExpoGo เราก็สามารถ เขียนพัฒนา Application ไปด้วยและเห็นผลลัพธ์ที่เรา เขียนพัฒนา ได้เลยทันที</p><p><a href="https://expo.dev/client">https://expo.dev/client</a></p><p>แต่ถ้าพัฒนา Application เสร็จเรียบร้อยแล้ว เราอยากได้ Application ของเราเอง Install ลงบนมือถือของเราเองหล่ะ โดยไม่ใช้ผ่าน ExpoGo ทำอย่างไรได้บ้าง มาดูกันเลย</p><h4><strong>วิธีใช้งาน EAS</strong></h4><ol><li>ติดตั้ง EAS CLI (ติดตั้งโดยใช้ CMD หรือ ​Terminal)</li></ol><pre>npm install -g eas-cli หรือ yarn global add eas-cli</pre><p>2. Login Expo account ของคุณ</p><pre>eas login</pre><p>3. สร้าง configuration file</p><pre>eas build:configure</pre><p>ดูรายละเอียดการตั้งค่าได้ที่ <a href="https://docs.expo.dev/build-reference/build-configuration/">คลิ๊ก.</a></p><p>4. รัน Build</p><p>ก่อนที่คุณจะรัน Build คุณจะต้องสร้างใบรับรอง Application ของคุณสามารถดูรายละเอียดได้ตามนี้</p><ul><li><a href="https://docs.expo.dev/build/setup/#android-app-signing-credentials">Signing credentials for Android</a>.</li><li><a href="https://docs.expo.dev/build/setup/#ios-app-signing-credentials">Signing credentials for iOS</a>.</li></ul><pre>eas build</pre><p>หรือคุณสามารถสร้าง Build ได้โดยตรงสำหรับแต่ละแพลตฟอร์ม ดังนี้</p><pre>eas build --platform android<br>หรือ<br>eas build --platform ios<br>หรือ<br>eas build --platform all</pre><p>เพียงเท่านี้คุณก็จะได้ Application ของคุณ ที่มีทั้ง Android และ IOS ที่สามารถ Download ได้จาก <a href="https://expo.dev/">https://expo.dev/</a></p><h4>สรุป</h4><p>EAS สร้างขึ้นมาเพื่อลดขั้นตอนในเวลาที่เราพัฒนา Mobile Application เสร็จเรียบร้อยแล้ว เราไม่จำเป็นต้องมา Config อะไรให้ยุ่งยากเปรียบเสมือนที่คนจัดการให้เรียบร้อย พร้อมติดตั้งใช้งานทดสอบ บน อุปกรณ์ มือถือ จริง</p><p>ฝาก กดไลค์ กดแชร์ กดติดตาม กดกระดิ่ง กริ๊งๆ แล้วมาพบกันในบทความหน้า ขอบคุณครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d41a20c7f7d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/foxbith/build-mobile-application-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-expo-application-services-eas-d41a20c7f7d5">Build Mobile Application ด้วย Expo Application Services (EAS)</a> was originally published in <a href="https://medium.com/foxbith">FOXBITH</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>