4.13.1.3–4.13.1.4 - Implementing, debugging and testing a solution (VB.NET)

4.13.1.3–4.13.1.4 - Implementing, debugging and testing a solution (VB.NET)

Turn a model into VB.NET data and instructions, then use logical reasoning, selected test data and user feedback to improve the solution. Section 4.13.1.3 concerns implementation and iterative development; 4.13.1.4 concerns testing and acceptance. This route uses written code practice and is incomplete: runnable support pending; the real Paper 1 is an onscreen practical examination.

Implementing models and algorithms

Implementation makes a design precise enough for a computer to carry out: the model becomes data structures, and its algorithms become instructions in a programming language. A rehearsal-booking model might contain a room capacity, remaining seats and reservation requests. An integer can represent a count of seats; a record or class can group a reservation's name, date and quantity. The chosen representation must support the operations the requirements demand.

Suppose one rehearsal initially has five seats available. A request must be a whole number from 1 to the number of seats left. A successful request reduces the available seats; a rejected request leaves them unchanged. This interface exposes the state change through a ByRef parameter and returns whether the request succeeded:

VB.NET
Option Strict On
Imports System

Module Program
    Function TryReserve(requestText As String,
                        ByRef seatsLeft As Integer) As Boolean
        Dim requested As Integer
        If Not Integer.TryParse(requestText, requested) Then
            Return False
        End If
        If requested < 1 OrElse requested > seatsLeft Then
            Return False
        End If
        seatsLeft -= requested
        Return True
    End Function

    Sub Main()
        Dim seatsLeft As Integer = 5
        Console.WriteLine(TryReserve("2", seatsLeft))
        Console.WriteLine(seatsLeft)
    End Sub
End Module

Trace the statements: parsing produces 2; both invalid-range comparisons are false; subtraction changes 5 to 3; the function returns True. The two output lines are True and 3. TryParse allows malformed input to be rejected without an unhandled conversion exception. The function assumes its caller supplies a non-negative seatsLeft; that assumption is part of the interface contract.

Debugging means locating and correcting a defect. A syntax error prevents source being compiled; a runtime error occurs while executing, such as accessing an invalid array index; a logical error can produce the wrong result without a crash. If the range test used requested >= seatsLeft, the request for the last available seats would wrongly fail. Compare the requirement with the condition, step through a failing case and inspect variable values. Change the cause, then repeat the failed test and earlier passing tests to detect a regression.

Critical-path prototyping

An iterative process develops a solution in small cycles: build a version, test it, obtain feedback and revise it. A prototype is an early version used to investigate a requirement, design decision or risk. It may be deliberately limited, but the limitation must be clear so that it is not mistaken for a finished solution.

Critical path first

Prioritising the essential chain of operations on which a useful solution depends, so that its feasibility and major risks are investigated early.

For the booking system, the essential path is receiving a request, checking availability, changing the stored count and reporting success or rejection. Test that path before polishing colours or adding optional reminders. If two users must book at once, a prototype of shared updates should investigate whether both can reserve the same final seat. A single-user console prototype cannot demonstrate that a concurrent system is safe.

An agile approach uses short development cycles and ongoing collaboration to adapt the working solution. It does not mean omitting requirements, documentation or tests. A useful cycle is: implement the reservation rule; check normal and edge cases; show the working interaction to the organiser; revise an unclear message; retest it. Keep versions and a short change record so that a later defect can be connected to its cause.

Continue this lesson.

You’re previewing NovaLearn without an account. Create a free account to read the rest.

Create free account