Giter Site home page Giter Site logo

-design--patterns's Introduction

Design patterns

Note
1.ตัว pattern ที่เหลือโอกาสใช้มันค่อนข้างต่ำมากถ้ามีเวลาผมจะมาทำต่อนะครับ
2.หากใครต้องการช่วยทำต่อหรือแก้ไขต่างๆ fork ออกไปแล้วทำ pull request เข้ามาจะเป็นพระคุณมากครับ
3.หากอ่านแล้วสงสัย หรือ อธิบายตรงไหนผิด ตั้งเป็น Issue ทิ้งไว้ก็ได้ เดี๋ยวจะกลับมาตอบขอรับ
3.เจ้าหนังสือด้านล่างผมไม่ได้เขียน แต่ผมเอารูปเขามาใช้เลยใส่เครดิตให้เขาเฉยๆ จะซื้อไม่ซื้อก็แล้วแต่ศรัทธาเลยละกัน ส่วนตัวผมว่าอ่านแล้วก็สนุกดี

มันคืออะไร ?

Design patterns เป็นแนวคิดในการแก้ปัญหาที่เราเจอบ่อยๆในการออกแบบซอฟต์แวร์ ซึ่งถ้าเรามี ปัญหา แล้วปัญหานั้นมีลักษณะตรงกับ pattern ไหนก็ตาม เราก็จะสามารถนำแนวคิดของ pattern นั้นๆไปแก้ปัญหาของเราได้เลย

Pattern แต่ละตัวจะเป็นแค่ แนวคิดในการแก้ไขปัญหา เท่านั้น ซึ่งมันไม่ได้บอกชัดเจนว่าเราต้องมีทำอะไรบ้างเพื่อจะแก้ปัญหาที่เจอ ดังนั้นวิธีการแก้ปัญหาที่เจอจะขึ้นกับการตัดสินใจของ developer เอง

👍 ข้อดี

  • เมื่อเกิดปัญหาในการออกแบบซอฟต์แวร์ สามารเอา pattern มาแก้ปัญหาได้เลย
  • สามารถรับมือเมื่อเจอกับ business requirement ที่ซับซ้อนได้
  • ลดการเกิด coupling, โค้ดยืดหยุ่นขึ้น, โค้ดนำกลับมาใช้ใหม่ได้

👎 ข้อเสีย

  • Design pattern แต่ละตัวไม่ได้เข้าใจง่ายสำหรับ developer มือใหม่
  • Developer ส่วนใหญ่จะนำ design pattern ไปใช้เลย โดยไม่ได้ชั่งน้ำหนักก่อนใช้ให้ดีก่อน ทำให้โค้ดมีความซับซ้อนเพิ่มขึ้นโดยไม่จำเป็น

คำเตือน
การนำ design pattern ไปใช้ไม่ใช่เรื่องเท่ เพราะมันมี cost (memory, processing overhead & complexity) ของมันค่อนข้างสูง ดังนั้นก่อนใช้ให้ ชั่งน้ำหนัก ข้อดี/ข้อเสีย ให้ดีก่อน ไม่งั้นโค้ดจะทำงานได้แต่ maintenance ยากขึ้นโดยใช่เหตุ ดังนั้นอย่าเมากาวแล้วตะบี้ตะบันเอา pattern ไปใช้เลยตลอดเวลา (อาตตามาเตือนแล้วนะ)

กลุ่มของ patterns ต่างๆ

Pattern ทั้งหมดถูกแบ่งออกเป็น 3 กลุ่ม ตามวัตถุประสงค์ในการแก้ไขปัญหาของมัน โดยแต่ละกลุ่มจะช่วยให้โค้ดนั้น ลดการเกิด coupling, มีความยืดหยุ่นขึ้นและนำกลับมาใช้ใหม่ได้

Credit

https://refactoring.guru
You can buy his book by click the image below.
img

-design--patterns's People

Contributors

sakul avatar nattatorn-dev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.