大三專題
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # MVC (Model,View,Controller) MVC 是一種==軟體架構模式==,把系統分為 Model, View, Controller。它的設計概念是以關注點分離(seperation of concerns, SOC)為基礎,將應用程式拆解成不同的功能面向,各自處理負責事項;強調團隊分工的概念。 這三個套用在 Web 分別為前端 HTML+CSS (View),後端 API 資料庫(Model),控制後端資料庫的接口 JavaScript (Controller)。 > 網站的開發過程中,如果沒有設立架構,需求要什麼就寫什麼,到最後,會留下一堆所謂的技術債,讓之後每次的更動,都得花較久的時間統整,或是有很多隱藏的Bug。 + View:前端畫面與邏輯顯示 + Controller:處理控制流程和回應 + Model:後端資料庫進行運作 </br> ## 流程 當 Controller 收到請求後,Controller 會通知 Model 調度資料,接著再把資料傳遞給 View 來產生樣板,在回傳給Controller進行回復,最終將呈現資料的 HTML 頁面回傳到客戶端的瀏覽器。 </br> ![image](https://hackmd.io/_uploads/Hybd9rqS6.png) ## View + View 常譯為「視圖」,View 所管理的功能層叫作「表現層 (presentation layer)」,顧名思義是負責管理畫面的呈現,也就是 HTML 樣板 (template),但實際回復使用者的還是得透過Controller。 + 在開發框架裡,因為 HTML template 會有需要以動態顯示資料的情況 (也就是由 Model 取出的資料內容),所以 View 會再進一步運用樣板引擎 (template engine) 將資料帶入 template。 </br> ![image](https://hackmd.io/_uploads/SkgaF3HS6.png) > notifications是一個陣列。陣列內裝有所有的 notification 資料,這是以迴圈的方式一筆一筆撈出 notifications 裡面所有的資料。 文法像是 {% 、{{ 則會根據不同語言的 HTML 產生引擎會有所不同。 ## Controller + Controller,是整個運作過程中的核心,負責收發 Request 與 Response ; 在Controller 會設置不同的事件(ation),觸發了不同的 action,Controller 就會啟動後續一系列的行為。 + Controller決定了應用程式的工作流程 (workflow),並且蒐集不同元件的工作結果,統一回傳給使用者。 ### 常見事件(ation)設計問題: + 使用者是否需要先登入 (認證) 才可以看到網頁內容? + 使用者是否只能閱讀資料,但不能修改或刪除? + 使用者新增了資料之後,會重新導向至哪個頁面? ## Model + Model,代表資料模型,主要負責==資料的操作與邏輯==,若使用者想要對資料進行「新增、修改、刪除、瀏覽」的動作,Model會跟軟體的資料庫進行溝通(例如:到資料庫提取該使用者的資料)。 + Model 幫忙去資料庫裡取出必要的資料,把資料放進應用程式裡的某個程式物件,然後才能用 JavaScript 去操作該物件。 > 不一定都使用JS,有些開發者會使用Java、Python、Ruby 或 .NET 等,處理商業邏輯和數據存取,以提供更為豐富和互動的用戶界面。 > 如今JS的發展日新月異,也能做到上述語言的擁有的邏輯操作,所以能考慮統合一種語言,來提升開發效率及便利性。 ### 範例 電商網站: + 會員購物有九折、訂單超過一定的金額免運費 + 檢查登入帳號的類型,並依此開放不同權限 社交網站: + 判斷使用者彼此之間的友好程度 To-do List: + 過了期但沒被執行的 to-dos 不能被刪除 這些邏輯出自於產品本身的需求或是規則。它們是==獨立於網頁介面的商業邏輯==,因此之後改變載體,如手機 App 等相關應用程式,這些商業邏輯在大部分情況是通用的。這些邏輯相關的程式碼應該被分類到對應的 Model 檔案裡。 ## MVC 架構的優劣 ### 優點: + 重複使用:由於 MVC 三塊獨立,同一套 Model,針對使用場景不一樣,透過不同的 View 來呈現,能最大化程式碼的使用效率。 + 容易維護:三塊獨立,可以讓你在不破壞現有架構下,進行擴充或修改,大幅提升開發效率。 + 明確分工:在實際工作時,能大致分兩塊 功能設計 與 網頁設計,以加快開發速度。 ### 缺點: + 不適合小型項目:對於小型或非常簡單的項目,MVC架構可能會引入不必要的複雜性和開發成本。 + 性能問題:在某些情況下,MVC架構可能會導致性能問題,例如,過多的數據綁定和模型更新可能影響用戶界面的響應速度。 ## 參考資料 [MVC架構是什麼?認識 Model-View-Controller 軟體設計模式][1] [「筆記」- 何謂 MVC 軟體設計模式][2] [1]: https://tw.alphacamp.co/blog/mvc-model-view-controller [2]: https://medium.com/pierceshih/%E7%AD%86%E8%A8%98-%E4%BD%95%E8%AC%82-mvc-%E8%BB%9F%E9%AB%94%E8%A8%AD%E8%A8%88%E6%A8%A1%E5%BC%8F-af1ff10901e6

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully