Program design tools
แนะนำใหม่
19:05
รอบชีวิตการพัฒนาโปรแกรม
บั๊กเล็กๆ หากหลุดออกไปจนถึงเวอร์ชันReleased อาจต้องใช้เงินมหาศาลในการแก้ไข — มากกว่ามากที่จะจับมันได้ตั้งแต่ต้น นั่นคือเหตุผลที่เราไม่เพียงแค่มารอพิมพ์โค้ด เราทำตาม…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| software engineering/ˈsɒftweə ˌendʒɪˈnɪərɪŋ/ | The planned work of making software that works well and is easy to manage. |
| code/kəʊd/ | Instructions written in a programming language for a computer to follow. |
| design stage | The stage of development that decides how a program will meet its requirements. |
| structure chart/ˈstrʌktʃə tʃɑːt/ | แผนภาพโครงสร้าง |
| state-transition diagram/steɪt trænˈsɪʃn ˈdaɪəɡræm/ | แผนภาพการเปลี่ยนสถานะ |
| pseudocode/ˈsuːdəʊkəʊd/ | รหัสจำลอง |
| Analysis/əˈnæləsɪs/ | The stage of development that identifies what a program must do. |
| data structures/ˈdeɪtə ˈstrʌktʃəz/ | A way of organising and storing data to support particular operations. |
| algorithms/ˈælɡərɪθəmz/ | A finite sequence of precise steps for solving a problem or carrying out a task. |
| modules/ˈmɒdjuːlz/ | Separately organised program components that perform defined tasks and communicate through interfaces. |
| interface/ˈɪntəfeɪs/ | A way for users or programs to communicate with the computer's hardware. |
| flowchart/ˈfləʊtʃɑːt/ | A diagram showing the sequence of steps and decisions in a process or algorithm. |
| logic/ˈlɒdʒɪk/ | The order of steps and decisions used to solve a problem. |
| transition/trænˈsɪʃn/ | A change from one state to another, caused by an event. |
| decomposition/ˌdiːkɒmpəˈzɪʃn/ | การแยกย่อย |
| subroutines/ˈsʌbruːtiːnz/ | ซับรูทีน |
| parameters/pəˈræmɪtəz/ | พารามิเตอร์ |
| top-down design/tɒp daʊn dɪˈzaɪn/ | การออกแบบจากบนลงล่าง |
| caller/ˈkɔːlə/ | The program or module that asks another module to run. |
| selection/sɪˈlekʃn/ | Choosing which branch of instructions to execute according to a condition. |
| loop/luːp/ | A structure that repeats a sequence of instructions. |
| Hierarchy/ˈhaɪərɑːki/ | An arrangement of modules in levels showing which modules call others. |
| return value/rɪˈtɜːn ˈvæljuː/ | The value a function passes back to the part of the program that called it. |
| header/ˈhedə/ | The first line of a subroutine, stating its name, parameters and any return type. |
| array/əˈreɪ/ | An indexed collection of elements arranged in one or more dimensions. |
| main program | The top-level part of a program that controls its overall tasks and calls subroutines. |
| procedure/prəˈsiːdʒə/ | A named sequence of instructions that performs a task when called. |
| function/ˈfʌŋkʃn/ | A mapping that assigns exactly one output to each allowed input. |
| passing modes | Ways of passing parameters that determine how a subroutine can use or change data. |
| states/steɪts/ | สถานะ |
| events/ɪˈvents/ | An occurrence detected by a program that can trigger a response. |
| action/ˈækʃn/ | Something a system does when an event causes a change of state. |
| start state | The state a system is in when it begins operating. |
| user interface/ˈjuːzə ˈɪntəfeɪs/ | The controls, displays and interaction mechanisms through which a person communicates with a computer system or program. |
| submodules | Smaller modules that carry out parts of the work of a larger module. |
ปีที่ซอฟต์แวร์กลายเป็นวิศวกรรม
- ในเดือนตุลาคม 1968 นักเขียนโปรแกรมชั้นนำของโลกห้าสิบคนมาพบกันที่การ์มิช ประเทศเยอรมนี เพื่อหารือว่าทำไมโปรแกรมขนาดใหญ่ถึงล้มเหลว: ล่าช้า เกินงบประมาณ ไม่เชื่อถือได้ They สร้างคำศัพท์สำหรับสิ่งที่ขาดหายไป: วิศวกรรมซอฟต์แวร์
- ข้อร้องเรียนนั้นเรียบง่าย ผู้สร้างวาดก่อนสร้าง วิศวกรคำนวณก่อนตัด นักเขียนโปรแกรมพิมพ์ code ก่อนใครจะวาดโปรแกรมออกมา
- ภาพวาดที่เกิดขึ้นในทศวรรษนั้นคือสิ่งที่คุณจะใช้ในช่วงการออกแบบ: แผนภูมิโครงสร้าง ซึ่งแสดงว่าโปรแกรมถูกแบ่งเป็นส่วนต่างๆ อย่างไร และ แผนภาพการเปลี่ยนสถานะ ซึ่งแสดงพฤติกรรมของมัน
- This lesson is how to read them, how to construct them, and how to turn a structure chart into pseudocode.
สิ่งที่การออกแบบตัดสินใจ
- Analysis บอก what โปรแกรมต้องทำ Design ตัดสินใจ how: โครงสร้างข้อมูล, อัลกอริทึม, โมดูล และอินเทอร์เฟซ
- ขั้น design ผลิตภาพวาดที่นักเขียนโปรแกรมสามารถ code จากได้: a flowchart สำหรับตรรกะของอัลกอริทึมเดียว, pseudocode สำหรับสิ่งเดียวกันในรูปแบบข้อความ, a structure chart สำหรับโมดูล, และ a state-transition diagram สำหรับพฤติกรรม
- แต่ละเครื่องมือตอบคำถามที่แตกต่างกัน, และการสอบถามว่าอันไหนเหมาะสมที่สุด
ตรรกะของอัลกอริทึมหนึ่ง, วาดไว้ก่อนการเขียนโค้ด
Software process lab
Classify development examples by the stage or tool they belong to.
The structure chart
- A structure chart แสดง decomposition แบบลำดับชั้นของโปรแกรมออกเป็นโมดูล, subroutines ของมัน, และ parameters ที่ส่งระหว่างกัน This top-down design แบ่งปัญหาใหญ่หนึ่งปัญหาออกเป็นปัญหาย่อยเล็กๆ หลายปัญหา, แต่ละอย่างกลายเป็นโมดูล
- แต่ละโมดูลเป็นสี่เหลี่ยมผืนผ้า เส้นเชื่อมผู้เรียก (caller) ด้านบนเข้ากับโมดูลที่ถูกเรียก ด้านล่าง โมดูลในระดับเดียวกันถูกเรียกจากซ้ายไปขวา
- ลูกศรเล็กข้างเส้นข้อมูลแสดงทิศทาง: พารามิเตอร์ที่ส่ง ลง ไปยังโมดูล และผลลัพธ์ที่ส่ง ขึ้น กลับไปยังผู้เรียก โมเดลสี่เหลี่ยมจตุรัสใช้แทนการเลือกเงื่อนไข ส่วนลูกศรโค้งใช้แทนลูป

Hierarchy on the lines, data on the arrows
A structure chart shows:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A structure chart is the hierarchical breakdown into modules, with parameters down and results up.
Breaking a problem into modules from the top down is called:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Top-down design produces a modular solution.
Worked example: read the signatures off the chart
CalculatePay
/ | \
GetEmployee CalculateBonus CalculateTax
returns: takes: sales takes: gross
employeeID returns: bonus returns: tax
GetEmployeeรับอะไรเลยและไม่ส่ง employee ID กลับ:FUNCTION GetEmployee() RETURNS INTEGERCalculateBonusรับ sales figure ลงไปและส่ง bonus กลับ:FUNCTION CalculateBonus(Sales : REAL) RETURNS REALCalculateTaxรับ gross pay และส่ง tax กลับ ลูกศรทุกเส้นบนแผนภาพคือ parameter หรือ return value ใน header; header ที่มี parameter แต่แผนภาพไม่แสดงถือว่าผิด
On a structure chart, a small arrow pointing down from the caller into a module shows a ____ passed to it.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Downward arrows are parameters going in; upward arrows are results returned. Together they give the module's header.
Worked example: construct a structure chart
- โปรแกรมอ่านคะแนนนักเรียน คำนวณค่าเฉลี่ย และแสดงผลเกรด วาดแผนภาพโครงสร้าง
- โมดูลบนสุดคือ
ProcessStudentด้านล่างจากซ้ายไปขวาคือReadMarksซึ่งส่งกลับค่าอาร์เรย์ของคะแนน;CalculateAverageซึ่งรับค่าอาร์เรย์คะแนนลงมาและส่งกลับค่าเฉลี่ย;OutputGradeซึ่งรับค่าเฉลี่ยลงมาและไม่ส่งค่าอะไรกลับ - สิ่งที่ต้องพิจารณาได้แก่: ระดับชั้นที่มีงานหลักอยู่ด้านบน งานย่อยตามลำดับการทำงาน และ ชื่อ พารามิเตอร์บนลูกศรที่ชี้ทิศทางถูกต้อง ลูกศรที่ไม่มีฉลากจะได้คะแนนสูงสุดเพียงครึ่งหนึ่งเท่านั้น

From structure chart to pseudocode
- โมดูลบนสุดจะกลายเป็นโปรแกรมหลัก ส่วนสี่เหลี่ยมผืนผ้าด้านล่างจะเป็น Procedure หรือ Function ที่อ่านชื่อจากลูกศร โปรแกรมหลักจะเรียกใช้งานตามลำดับจากซ้ายไปขวา
PROCEDURE ProcessStudent()
DECLARE Marks : ARRAY[1:10] OF INTEGER
DECLARE Average : REAL
Marks ← ReadMarks()
Average ← CalculateAverage(Marks)
CALL OutputGrade(Average)
ENDPROCEDURE
- ค่าที่ถูกส่งคืนหมายถึง a
FUNCTION … RETURNS; modul ที่ไม่ส่งค่ากลับคือ aPROCEDUREรายการ parameter คือลูกศรชี้ลงทั้งหมด
Put the steps of designing a program with a structure chart in order.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Top down: task, sub-tasks, data flow, headers, calls. The chart is finished before the first line of code.
A module whose result is returned for use in an expression should be written as a PROCEDURE.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A value returned for use in an expression requires a FUNCTION … RETURNS. A PROCEDURE can pass results back through BYREF parameters.
The state-transition diagram
- A state-transition diagram document behaviour ของระบบ: states ที่มันอาจอยู่ในนั้น และ events ที่ย้ายมันจาก state หนึ่งไปอีก state หนึ่ง
- แต่ละ state เป็นวงกลมหรือกล่องมุมมน; แต่ละ transition เป็นลูกศรที่มี label เป็น event ที่ก่อให้เกิดมัน, บางครั้งมี action ที่ดำเนินการ Marker แสดง start state
- It suits systems that wait for events and react: a vending machine, a traffic light, a door lock, a user interface

Every state, every event, every arrow
A state-transition diagram shows:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
States are circles; transitions are event-labelled arrows. Ideal for vending machines, locks, traffic lights.
What does a state-transition diagram show? Select ทั้งหมด that apply.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
States, labelled transitions and the start marker. Timing is not part of the diagram.
Worked example: read the door-lock diagram
- กุญแจจะเปิดด้วยรหัส 2, 5, 9 เริ่มต้นที่ Locked การกด 2 จะเปลี่ยนสถานะเป็น One digit correct; จากนั้นการกด 5 จะย้ายไปยัง Two digits correct; และจากนั้นการกด 9 จะย้ายไปยัง Unlocked.
- Any other key from any of the waiting states returns to Locked: the diagram shows those arrows too, and a diagram that leaves them out has a gap. What happens if 2 is pressed while Unlocked? If no arrow says, the design has not decided.
- นั่นคือหน้าที่ของแผนภาพ: ทุกสถานะต้องระบุสิ่งที่เกิดขึ้นต่อทุกเหตุการณ์ ดังนั้นการเปลี่ยนแปลงที่ขาดหายไปจึงถูกหาได้บนกระดาษและไม่ใช่โดยลูกค้า

A state-transition diagram makes missing or unhandled transitions easy to spot, because every state and the events between them are laid out.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Seeing every state and event reveals cases you have not handled — e.g. an unexpected second coin in a vending machine.
การเลือกเครื่องมือ
- เพื่อแสดงว่าโปรแกรมถูก แบ่งออกเป็นโมดูล และสิ่งใดถูกส่งผ่านระหว่างกัน: แผนภาพโครงสร้าง (structure chart)
- เพื่อแสดงว่าระบบ มีพฤติกรรมอย่างไรตามเวลา เมื่อได้รับเหตุการณ์ โดยเฉพาะเครื่องจักรหรืออินเทอร์เฟซที่มีโหมดต่างๆ: แผนภาพการเปลี่ยนสถานะ (state-transition diagram)
- เพื่อแสดง ตรรกะแบบขั้นตอน ของอัลกอริทึมหนึ่ง: ใช้แผนภาพไหล (Flowchart) หรือ伪代码 (Pseudocode) ระบุชนิดและเหตุผล

Match each design tool to what it shows.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Each tool views the design differently — structure (modules), behaviour (states), flow (flowchart) or steps (pseudocode).
A traffic-light controller must respond to a timer and a pedestrian button. Which design tool documents its behaviour best?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Red, red-and-amber, green, amber are states; the timer and the button are events. A structure chart would show the modules, not the behaviour.
คะแนนที่หลุดหายไป
- แผนภาพโครงสร้าง ไม่ใช่แผนภาพไหล มันแสดงลำดับชั้นและพารามิเตอร์ ไม่ใช่ลำดับของการตัดสินใจภายในโมดูล
- ตั้งชื่อให้ทุกลูกศรด้วย ชื่อ ของพารามิเตอร์หรือผลลัพธ์ และชี้ไปทางที่ถูกต้อง ลูกศรเปล่าไม่สื่ออะไรเลย
- สถานะคือ สภาวะ ที่ระบบกำลังอยู่ในนั้นและกำลังรอ; เหตุการณ์คือสิ่งที่เกิดขึ้นกับมัน "กด 5" เป็นเหตุการณ์ ไม่ใช่สถานะ
- หัวข้อของ伪代码 ต้อง ตรงกับแผนภาพ: พารามิเตอร์เดียวกัน ค่าที่ส่งคืนเดียวกัน และลำดับการเรียกใช้เหมือนกัน
คุณเข้าใจแล้ว
- แผนภาพโครงสร้าง แสดงการแยกส่วนแบบลงสู่ระดับล่าง (top-down decomposition) เข้ากับโมดูลต่างๆ พร้อม พารามิเตอร์ ที่ส่งลง และ ผลลัพธ์ ที่ส่งกลับขึ้นบนลูกศรที่มีฉลาก
- อ่านหัวข้อ伪代码 ออกจากมัน: ลูกศรชี้ลงคือรายการพารามิเตอร์, ลูกศรชี้ขึ้นทำให้มันเป็น
FUNCTION … RETURNS, และโมดูลหลักเรียกใช้จากซ้ายไปขวา - แผนภาพการเปลี่ยนสถานะ แสดง สถานะ และ เหตุการณ์ ที่ทำให้เคลื่อนย้ายระหว่างกัน และเปิดเผยการเปลี่ยนแปลงที่ไม่มีใครตัดสินใจ
- การแยกส่วน → แผนภาพโครงสร้าง; พฤติกรรม → แผนภาพการเปลี่ยนสถานะ; ตรรกะของอัลกอริทึมหนึ่ง → แผนภาพไหลหรือ伪代码
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้