Development process, testing and debugging, OOP and developer obligations: WACE Computer Science Unit 3
“Apply a software development framework and good programming practice, test and debug programs (types of errors, test data, debugging techniques), use object-oriented programming concepts, and explain developers' legal and ethical obligations”
Follow a development framework with good practice (clear names, comments, modularity, validation, version control). Test with normal, boundary and invalid data and debug with traces and breakpoints to find syntax, runtime and logic errors. OOP uses classes, objects, encapsulation, inheritance and polymorphism, and developers must meet legal and ethical obligations.
Jump to a section
What this dot point is asking
Beyond writing code, you need to know how professional software is developed: following a development framework and good practice, testing and debugging systematically, using object-oriented programming (OOP), and meeting legal and ethical obligations.
The answer
Development framework and good practice
A typical framework: analyse (requirements), design (algorithms, data structures, interfaces), develop (code), test, implement, evaluate and maintain. It may be followed sequentially (waterfall) or in iterations (agile).
Good practice: meaningful identifiers, consistent indentation, comments explaining why, modular functions, avoiding global variables, input validation, and version control.
Testing and debugging
- Errors: syntax (breaks language rules), runtime (fails while running), logic (runs but gives wrong results).
- Test data: normal, boundary (edges and just outside) and invalid (wrong type or out of range), each with expected results in a test table.
- Levels: unit, integration, system and acceptance testing.
- Debugging techniques: trace tables, print statements, breakpoints and stepping, watching variables, rubber-duck explaining.
Object-oriented programming
- Class: a template of attributes and methods. Object: an instance of a class.
- Encapsulation: hide data inside the class; access it through methods.
- Inheritance: subclasses reuse and extend a parent class.
- Polymorphism: the same method call behaves appropriately for different object types.
- Abstraction: expose only what users of the class need.
Developers' obligations
- Legal: copyright and licences (including open-source licence conditions), privacy law when handling personal information, accessibility requirements.
- Ethical: secure coding, honesty about limitations, avoiding bias, protecting user data, professional codes of conduct.
Debugging a logic error in: average = total / count, where count is set to the number of lines in a file including a header row.
- Symptom: averages are slightly too low.
- Trace: with 3 data rows plus a header, count = 4.
- Cause: the header is counted as data.
- Fix: count only data rows (count = lines minus 1) and add a test with a known answer.
- Only testing normal data
- Boundary and invalid data find most bugs.
- Confusing runtime and logic errors
- Runtime errors crash; logic errors give wrong answers.
- Using inheritance where objects just share a value
- Inheritance is for "is a" relationships.
Practice questions
Original practice questions graded from foundation to exam level, each with a full worked solution. Try them before revealing the solution.
foundation3 marksClassify each error: (a) a missing closing bracket, (b) a program that calculates the average by dividing by the wrong count, (c) a program that crashes when a file is missing.Show worked solution →
(a) Syntax error: breaks the language rules, so the program will not run or compile.
(b) Logic error: the program runs but gives the wrong result.
(c) Runtime error: occurs while the program is running, when an operation cannot be completed.
Marking guide: 1 mark each.
core4 marksA function accepts an age from 13 to 19 for a youth program. Design test data with expected results.Show worked solution →
| Test data | Type | Expected |
|---|---|---|
| 16 | Normal | Accepted |
| 13 | Boundary | Accepted |
| 19 | Boundary | Accepted |
| 12 | Boundary (outside) | Rejected |
| 20 | Boundary (outside) | Rejected |
| "sixteen" | Invalid type | Rejected with an error message |
Marking guide: 1 mark for normal data, 2 marks for boundary values on both sides, 1 mark for invalid data with expected results.
exam6 marksDesign a class structure for a library system with a parent class Item and subclasses Book and DVD. Show attributes and methods, and explain how inheritance, encapsulation and polymorphism are used.Show worked solution →
Item (parent): private attributes itemID, title, isOnLoan; methods borrow(), returnItem(), getLoanPeriod().
Book (inherits Item): extra attribute author; overrides getLoanPeriod() to return 21 days.
DVD (inherits Item): extra attribute runtime; overrides getLoanPeriod() to return 7 days.
- Inheritance
- Book and DVD reuse itemID, title, borrow() and returnItem() from Item, avoiding duplicated code.
- Encapsulation
- isOnLoan is private and changed only through borrow() and returnItem(), preventing invalid states such as an item being loaned twice.
- Polymorphism
- calling getLoanPeriod() on any Item returns the right period for its actual type, so the loan system can treat all items the same way.
Marking guide: 2 marks for a correct structure, 1 mark each for inheritance, encapsulation and polymorphism explained (3 marks), 1 mark for a clear, justified design.
core4 marksUsing a BankAccount class with a balance attribute and deposit() and withdraw() methods as an example, explain the difference between encapsulation and abstraction.Show worked solution →
Encapsulation bundles the data and the methods that act on it inside the class, and restricts direct access to the data. In BankAccount, balance is private, so other code cannot write account.balance = 1000000. It can only change balance through deposit() and withdraw(), which can check the input (for example, reject a negative deposit or a withdrawal larger than the balance). This protects the object from invalid states.
Abstraction means exposing only what users of the class need and hiding how it works. A programmer using BankAccount only needs to know that withdraw(amount) takes money out; they do not need to know how the balance is stored or how the checks are coded, so the inner code can change without affecting them.
In short, encapsulation is about protecting the data, while abstraction is about presenting a simple interface.
Marking guide: 1 mark for defining encapsulation, 1 mark for applying it to balance and the methods, 1 mark for defining abstraction, 1 mark for applying it to the BankAccount example (4 marks).
exam5 marksA developer is building a free study-planner app for students. The app uses an open-source library for its calendar, and it collects each student's name, email address and school. Explain two legal obligations and one ethical obligation the developer has in this situation.Show worked solution →
- Legal obligation 1: copyright and licences
- The open-source library is still protected by copyright. The developer must comply with its licence conditions, such as keeping the copyright and licence notices, and meeting any conditions on sharing the app's own source code if the licence requires it. Using it outside those conditions would breach copyright.
- Legal obligation 2: privacy law
- Names, email addresses and schools are personal information. The developer must handle them as privacy law requires, for example collecting only what the app needs, telling users what is collected and why, storing it securely and not using it for unrelated purposes.
- Ethical obligation: protecting user data and secure coding
- Even beyond the legal minimum, the users are students who trust the app with their details. The developer should write secure code (such as validating input and protecting stored data) and be honest with users about the app's limitations and what happens to their data.
Marking guide: 2 marks for each legal obligation explained and applied to the app (1 mark for identifying it, 1 mark for applying it), 1 mark for an ethical obligation explained (5 marks).
exam16 marksA small medical clinic wants an app that lets patients book appointments. Each appointment length must be a whole number of minutes from 15 to 60 inclusive. The clinic manager is not sure of all the features she needs and wants to try early versions. (a) Describe four stages of a software development framework, applying each to the booking app. (4 marks) (b) Recommend whether the developer should follow a waterfall or an agile approach, and justify your recommendation. (3 marks) (c) Design a test table for the appointment length input, with normal, boundary and invalid test data and the expected result for each. (4 marks) (d) Classify each error and explain your answer: (i) the program stops with an error when a patient's record file is missing; (ii) the keyword WHILE is spelt WHLIE; (iii) a 30-minute appointment is shown as ending 20 minutes after it starts. (3 marks) (e) State one legal and one ethical obligation the developer has when storing patients' details. (2 marks)Show worked solution →
(a) Any four of:
- Analyse: meet the clinic manager and staff to gather requirements, such as booking, cancelling and the 15 to 60 minute rule.
- Design: plan the screens, the data to store (patients, appointments) and the algorithms, such as checking that a time slot is free.
- Develop: write the code using good practice, such as meaningful names, comments and modular functions, with version control.
- Test: test each function and the whole system with normal, boundary and invalid data.
- Implement: install the app for the clinic and train the staff.
- Evaluate and maintain: check the app meets the requirements and fix bugs or add features after release.
(b) Agile. The manager does not yet know all the features she needs and wants to try early versions. Agile builds the app in short iterations, releasing working versions for her feedback so requirements can change between iterations. Waterfall follows the stages in sequence and needs the requirements fixed at the start, so late changes would be costly.
(c)
| Test data | Type | Expected result |
|---|---|---|
| 30 | Normal | Accepted |
| 15 | Boundary | Accepted |
| 60 | Boundary | Accepted |
| 14 | Boundary (just outside) | Rejected with a message |
| 61 | Boundary (just outside) | Rejected with a message |
| 22.5 | Invalid (not a whole number) | Rejected with a message |
| "half an hour" | Invalid (wrong type) | Rejected with a message |
(d)
- (i) Runtime error: the code is valid, but an operation (opening the file) cannot be completed while the program runs, so it crashes.
- (ii) Syntax error: WHLIE breaks the rules of the language, so the program will not run or compile.
- (iii) Logic error: the program runs but gives the wrong result, so the end time calculation is wrong.
(e) Legal: comply with privacy law when handling patients' personal information, for example collecting only what is needed and storing it securely. Ethical: protect user data through secure coding, or be honest with the clinic about the app's limitations.
Marking guide: (a) 1 mark for each of four stages correctly applied to the app (4 marks). (b) 1 mark for recommending agile, 2 marks for justification linked to changing requirements and early versions (3 marks). (c) 1 mark for normal data, 1 mark for boundary values inside the range, 1 mark for boundary values just outside, 1 mark for invalid data, all with expected results (4 marks). (d) 1 mark for each correct classification with a reason (3 marks). (e) 1 mark for a legal obligation, 1 mark for an ethical obligation (2 marks). Total 16 marks.
exam18 marksA school sports department hires out equipment to students. Every item has an item ID, a name and a daily hire rate, which must be more than 0 and at most 50 dollars. Racquets also have a grip size, and every racquet hire has a flat 2 dollar cleaning fee added. Balls have no extra data or fees. (a) Draw or describe a class structure with a parent class Equipment and subclasses Racquet and Ball, showing the attributes and methods of each. (4 marks) (b) Write Python code for Equipment, with private attributes, a getter and a validating setter for the daily rate, and a method hire_cost(days), and for Racquet, which overrides hire_cost. (6 marks) (c) A list holds a Racquet with a daily rate of 4 dollars and a Ball with a daily rate of 1.50 dollars. Explain how polymorphism applies when the program calls hire_cost(3) on each item in the list, and state each result. (3 marks) (d) Explain one way inheritance makes this program easier to maintain, and why Racquet should inherit from Equipment. (2 marks) (e) Design three unit test cases for the setter for the daily rate, giving the test data and expected result for each. (3 marks)Show worked solution →
(a)
- Equipment (parent): private attributes item_id, name, daily_rate; methods get_name(), get_daily_rate(), set_daily_rate(rate), hire_cost(days).
- Racquet (inherits Equipment): extra private attribute grip_size; overrides hire_cost(days) to add the 2 dollar cleaning fee.
- Ball (inherits Equipment): no extra attributes; uses the inherited hire_cost(days).
(b)
class Equipment:
def __init__(self, item_id, name, daily_rate):
self.__item_id = item_id
self.__name = name
self.__daily_rate = 0
self.set_daily_rate(daily_rate)
def get_name(self):
return self.__name
def get_daily_rate(self):
return self.__daily_rate
def set_daily_rate(self, rate):
if rate <= 0 or rate > 50:
raise ValueError("Daily rate must be more than 0 and at most 50")
self.__daily_rate = rate
def hire_cost(self, days):
return self.__daily_rate * days
class Racquet(Equipment):
def __init__(self, item_id, name, daily_rate, grip_size):
super().__init__(item_id, name, daily_rate)
self.__grip_size = grip_size
def hire_cost(self, days):
# add the flat 2 dollar cleaning fee to the normal cost
return super().hire_cost(days) + 2
class Ball(Equipment):
pass
The double underscore makes the attributes private, so other code must use the getter and setter, and the setter rejects invalid rates.
(c) Polymorphism means the same method call behaves appropriately for each object's actual type. The loop calls item.hire_cost(3) on every item without checking its type. For the Racquet, Python runs the overriding Racquet version: 4 x 3 + 2 = 14 dollars. For the Ball, it runs the inherited Equipment version: 1.50 x 3 = 4.50 dollars.
(d) Shared code, such as set_daily_rate and its validation, is written once in Equipment. If the rule changes (for example, a new maximum rate), it is changed in one place and every subclass gets the change, avoiding duplicated code and inconsistent fixes. Inheritance suits an "is a" relationship, and a racquet is a piece of equipment.
(e)
| Test data | Type | Expected result |
|---|---|---|
| 20 | Normal | Accepted; get_daily_rate() returns 20 |
| 50 | Boundary | Accepted; get_daily_rate() returns 50 |
| 0 | Boundary (just outside) | ValueError raised; the rate is unchanged |
Other suitable cases: 51 (rejected) or a negative value such as minus 5 (rejected).
Marking guide: (a) 1 mark for Equipment's attributes, 1 mark for its methods, 1 mark for Racquet's extra attribute and overridden method, 1 mark for Ball shown as a subclass (4 marks). (b) 1 mark for private attributes, 1 mark for the constructor, 1 mark for the getter, 1 mark for the setter with correct validation, 1 mark for hire_cost, 1 mark for Racquet inheriting and overriding hire_cost correctly (6 marks). (c) 1 mark for explaining polymorphism, 1 mark for 14 dollars, 1 mark for 4.50 dollars (3 marks). (d) 1 mark for the maintenance benefit, 1 mark for the "is a" relationship (2 marks). (e) 1 mark for each test case with data and expected result (3 marks). Total 18 marks.