Chapter overview and learning outcomes
This chapter develops foundational undergraduate knowledge in programming and object-oriented design, connecting theory with practical software engineering decisions. It is designed for active study: read each section, work through the examples, draw the diagrams from memory and complete the revision questions.
- Define and explain the central concepts using accurate technical terminology.
- Apply the methods to a realistic software engineering scenario.
- Compare alternatives and justify design or process decisions.
- Identify assumptions, risks, limitations and quality implications.
- Communicate technical reasoning with clear diagrams and evidence.
1. Programming as problem solving
Programming is the construction of precise instructions that a computing system can execute. A programmer first understands the problem, identifies inputs and outputs, states assumptions and constraints, decomposes the task and designs an algorithm. Coding is only one stage. A useful problem-solving cycle is understand, model, design, implement, test, explain and improve. Small examples reveal misunderstandings before large implementations are attempted. Edge cases such as empty input, extreme values, invalid data and unexpected ordering should be considered from the beginning.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
2. Algorithms, pseudocode and flowcharts
An algorithm is a finite, unambiguous sequence of steps for solving a problem. Pseudocode expresses logic without committing to a particular programming language. Flowcharts represent control flow using standard symbols for actions, decisions, input and output. A good algorithm has clearly defined inputs, outputs, preconditions and postconditions. Correctness means that it produces the required result for every input within its stated domain. Efficiency considers time and memory use. Before implementation, trace an algorithm manually using representative and boundary values.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
3. Programming paradigms and language choice
Procedural programming organises computation around procedures and state changes. Object-oriented programming organises software around objects that combine state and behaviour. Functional programming emphasises expressions, functions and controlled side effects. Declarative approaches describe what result is required rather than every operational step. Languages differ in type systems, runtime models, memory management, ecosystem and deployment. Language choice should reflect problem requirements, team expertise, maintainability, security, performance and available libraries rather than popularity alone.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
4. Variables, types, expressions and operators
A variable is a named reference or storage location whose value may change according to language semantics. Types classify values and determine permitted operations. Primitive types commonly include integers, floating-point numbers, booleans and characters; composite types include arrays, records, objects and collections. Expressions combine values and operators to produce results. Operator precedence and type conversion can create subtle defects. Strong typing and explicit validation can prevent some invalid operations, but developers must still understand overflow, precision, nullability and representation.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
5. Control structures and iteration
Sequence executes statements in order. Selection chooses a path using conditions, commonly through if/else or switch constructs. Iteration repeats work using loops such as for, while or foreach. Loop design requires an initial state, continuation condition and update that ensures progress toward termination. Off-by-one errors, accidental infinite loops and mutation during iteration are common problems. Nested loops can increase time complexity rapidly. Use clear conditions, meaningful names and small functions to make control flow easier to reason about.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
6. Functions, parameters, scope and modularity
Functions package behaviour behind a name and parameter list. They may return values, modify state or perform effects such as writing a file. Parameters can be passed by value, reference or other language-specific mechanisms. Scope determines where a name is visible; local scope reduces unintended coupling. Pure functions return results based only on their inputs and are easier to test. Cohesive functions perform a focused task. Modules group related responsibilities and expose intentional interfaces while hiding implementation details.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
7. Errors, exceptions and defensive programming
Errors may arise from invalid input, unavailable resources, programming defects or external service failures. Defensive programming makes assumptions explicit and checks conditions at trust boundaries. Exceptions communicate exceptional conditions but should not be used as ordinary control flow. Error messages should help users recover without exposing secrets or internal stack traces. A robust application distinguishes recoverable failures from fatal conditions, logs diagnostic context safely and cleans up resources. Silent failure is dangerous because it creates false confidence.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
8. Classes, objects and encapsulation
A class defines a type or blueprint; an object is an instance with identity, state and behaviour. Encapsulation groups data and operations and controls access to internal state. Public methods form a contract; private implementation details may change without affecting callers when the contract remains stable. Invariants are conditions that must remain true for an object to be valid. Constructors establish valid initial state, while methods preserve invariants. Avoid exposing mutable internal collections unless ownership and mutation rules are clear.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
9. Abstraction, inheritance and polymorphism
Abstraction expresses essential behaviour while hiding unnecessary detail. Inheritance allows a subtype to reuse or specialise behaviour from a base type, but deep hierarchies can create fragile dependencies. Polymorphism allows code to work through a common interface while different implementations provide different behaviour. Substitutability requires that a subtype honour the expectations of its base contract. Prefer composition when behaviour can be assembled from collaborating objects without creating an artificial taxonomic relationship.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
10. Interfaces, dependency management and design principles
An interface specifies a contract that implementations agree to provide. Dependency inversion encourages high-level policy to depend on abstractions rather than concrete low-level details. Dependency injection supplies collaborators from outside a component, improving testability and flexibility. The single-responsibility principle encourages cohesive modules; open-closed thinking favours extension without uncontrolled modification; interface segregation avoids forcing clients to depend on methods they do not use. These principles are guides for managing change, not mechanical rules.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
11. Testing, debugging and code quality
Unit tests check small units; integration tests examine collaboration; system tests evaluate the integrated application. Tests should cover normal, boundary and failure cases. Assertions express expected behaviour. Debugging uses reproducible steps, logs, breakpoints and hypothesis testing to locate causes rather than merely symptoms. Static analysis can identify suspicious patterns before execution. Code review evaluates correctness, readability, security and maintainability. A passing test suite provides evidence, not mathematical proof that all defects are absent.
Engineering application and analysis
Apply this concept to a realistic software project. Identify the actors, inputs, outputs, constraints, dependencies and failure conditions. Explain why the selected method is appropriate, what assumptions it makes, and how its success could be evaluated. Compare at least one alternative and discuss the consequences for maintainability, reliability, security, accessibility, performance and cost. Distinguish evidence from opinion, and state what additional information would be needed before making a production decision.
Worked study activity
Construct a small example, annotate each step, and test both an ordinary case and a boundary case. Record the expected result before running the test, compare the observed result, investigate any difference, and explain the lesson. Where a design choice is involved, write down the trade-off and identify who is affected by it.
Conceptual learning diagram; adapt it to the system or example being studied.
Conceptual learning diagram; adapt it to the system or example being studied.
Conceptual learning diagram; adapt it to the system or example being studied.
Practical laboratory / project activity
- Choose a bounded problem relevant to this chapter and describe the intended users and context.
- Write down assumptions, constraints, inputs, outputs and measurable success criteria.
- Develop a small prototype, model, algorithm, specification or test artefact.
- Use version control and document tools, versions and important decisions.
- Test normal, boundary and failure conditions; retain reproducible evidence.
- Review the result for usability, accessibility, security, reliability and maintainability.
- Submit a concise report explaining the method, findings, limitations and next steps.
Only test systems and datasets for which you have permission. Protect personal information and follow institutional academic-integrity and laboratory rules.
Worked reasoning and self-assessment
Begin with a precise problem statement. Separate known facts from assumptions. Identify the relevant concepts and choose a method that fits the problem constraints. Work through a small example manually, then verify the result using a suitable tool or test. Explain why the approach works, where it may fail, and what evidence would be needed to trust it in a larger system. For a design decision, state the alternatives and the trade-offs rather than presenting one choice as universally best.
Examination and revision questions
Attempt each question before opening the answer guidance. Use examples, diagrams and precise definitions in longer responses.
What is an algorithm?
Show answer guidance
A finite, unambiguous sequence of steps for solving a defined problem.
What is pseudocode?
Show answer guidance
A language-independent way to express algorithmic logic.
Name three programming paradigms.
Show answer guidance
Procedural, object-oriented, functional and declarative programming.
What is a variable's type?
Show answer guidance
A classification defining the values it can represent and operations permitted on them.
Why are loop invariants useful?
Show answer guidance
They help reason about correctness by stating what remains true through iterations.
What is a pure function?
Show answer guidance
A function whose result depends only on its inputs and that has no observable side effects.
Define encapsulation.
Show answer guidance
Bundling state and behaviour while controlling access to internal representation.
Differentiate a class and an object.
Show answer guidance
A class defines a type or blueprint; an object is an instance of that type.
What is polymorphism?
Show answer guidance
Using a common interface with different implementations providing specialised behaviour.
When may composition be preferable to inheritance?
Show answer guidance
When behaviour can be assembled from collaborators without creating a fragile or artificial subtype relationship.
What is dependency injection?
Show answer guidance
Supplying a component's dependencies externally rather than constructing them internally.
What is exception handling?
Show answer guidance
A mechanism for detecting and managing exceptional execution conditions.
Name three test levels.
Show answer guidance
Unit, integration, system and acceptance testing.
Why use code review?
Show answer guidance
To identify defects and improve readability, security, consistency and maintainability.
What is defensive programming?
Show answer guidance
Making assumptions explicit and validating conditions to reduce failures.
Revision checklist
- Can I define the chapter's key terms accurately?
- Can I explain the diagrams without reading the captions?
- Can I apply the ideas to a new project scenario?
- Can I justify a method and compare it with alternatives?
- Can I identify risks, assumptions and quality implications?
- Can I explain what evidence would validate my conclusion?
Further reading and academic practice
Use current university textbooks, peer-reviewed software engineering research, recognised standards and official technical documentation. Verify edition, version, publication date and applicability before citing a source. Cite quotations, data, diagrams, software and ideas according to your institution's required referencing style. Do not invent references, results or test evidence. Compare sources critically and note where professional guidance differs by context or jurisdiction.