跳到主要内容
英国伦敦 · 创立于 1994 年
中文

Unit 5: Designing and Building Software

The principles that make software easier to understand and change, how teams collaborate using version control and structured development processes, and how to continue learning computer science.

Unit 5 of 5 · about 54 minutes

5.1 Software design principles

Small programs can be written in almost any way and still work. Larger systems, maintained by many people over many years, are different. Most of the cost of software comes after its first release, as it is fixed, extended and adapted to new needs. Software design is about structuring code so that it remains understandable and safe to change. The principles below are widely taught and apply across languages.

Abstraction

Abstraction means hiding unnecessary detail behind a simpler interface. When you call a function named send_invoice, you should not need to know how the email server works. Well-designed abstractions let people work on one part of a system without understanding every other part. Operating systems, databases and programming languages are themselves layers of abstraction over the hardware.

Modularity, cohesion and coupling

A modular system is divided into separate parts, or modules, each responsible for one area, such as billing, user accounts or reporting. Two related ideas describe good modules:

  • High cohesion: everything inside a module belongs together and serves one clear purpose.
  • Low coupling: modules depend on each other as little as possible and only through clearly defined interfaces.

When coupling is low, a change to the reporting module is unlikely to break billing. When coupling is high, every change risks unexpected side effects elsewhere, and teams become reluctant to change anything.

Other widely used principles

  • Do not repeat yourself (DRY): each piece of knowledge, such as a tax rule, should live in one place. Duplicated logic tends to drift apart when only one copy is updated.
  • Keep it simple: prefer the simplest design that meets the real requirement. Unnecessary complexity is a frequent source of defects.
  • Separation of concerns: keep different responsibilities apart, for example separating how data is displayed from how it is stored and how business rules are applied.
  • Single responsibility: each function, class or module should have one reason to change.
  • Do not build what you do not yet need: designing for many imagined future requirements often produces complicated code for features that never arrive.

Object-oriented and functional styles

Programming languages encourage different styles. In object-oriented programming, code is organised around objects that combine data with the operations that act on it. A BankAccount object might hold a balance and offer deposit and withdraw operations, while preventing other code from changing the balance directly, a principle called encapsulation. Classes can share behaviour through inheritance, though experienced designers use this sparingly. In functional programming, the emphasis is on functions that take inputs and return outputs without changing shared data, which makes behaviour easier to predict and test. Many modern languages support both styles.

Remember: Code is read far more often than it is written. Clear names, small focused functions and consistent structure are not luxuries; they are what make software maintainable.

Technical debt

Teams sometimes take shortcuts to meet a deadline, such as copying code instead of restructuring it or skipping tests. The future cost of these shortcuts is called technical debt, because like financial debt it accrues "interest": each later change takes longer and carries more risk. Some debt is a reasonable business choice, but it should be visible, recorded and paid down deliberately rather than allowed to accumulate unnoticed. Refactoring, improving the structure of code without changing its behaviour, is the main way of reducing it, ideally supported by automated tests that confirm nothing has broken.

Architecture at a larger scale

At the level of whole systems, similar ideas apply. Many applications use a client-server design, with a browser or mobile app talking to services over the network through an API (application programming interface), a defined set of requests and responses. Some organisations split large systems into many small, independently deployed services; others keep a single well-structured application. Each approach has trade-offs in complexity, cost and speed of change, and neither is right for every situation.

In practice

If you manage or commission software, ask how it is structured, how easy it is to change one feature without affecting others, and whether the team tracks technical debt. If a team says that small changes take weeks and frequently break other features, that is a strong sign of high coupling and accumulated debt, and investment in refactoring may be more valuable than new features.

5.2 Version control and the development lifecycle

Software is rarely built by one person working alone. Teams need to share code, combine changes safely, track what changed and why, and release new versions without disrupting users. This lesson introduces the tools and processes that make this possible.

Version control

A version control system records every change made to a set of files over time. The most widely used today is Git, usually combined with an online hosting service where teams store, review and discuss code. Key concepts include:

  • Repository: the project's files together with their complete history.
  • Commit: a saved snapshot of changes, with a message explaining what changed and why.
  • Branch: a separate line of development, so a new feature can be built without disturbing the working version.
  • Merge: combining the changes from one branch into another.
  • Pull request or merge request: a proposal to merge a branch, where colleagues review the changes before they are accepted.

Version control means that any previous version can be recovered, that it is clear who changed what and when, and that several people can work on the same project at once. When two people change the same lines, the system flags a merge conflict for a person to resolve.

Tip: Write commit messages that explain why a change was made, not only what changed. "Fix rounding so totals match invoices" is far more useful to a future reader than "update file".

Code review

In many teams, no change reaches the main version without another developer reviewing it. Review catches defects, spreads knowledge of the code across the team, and keeps style and design consistent. Good reviews are specific, respectful and focused on the code rather than the person. Reviewers typically check that the change does what it claims, that it is tested, that it handles errors and unusual inputs, that it introduces no obvious security weakness and that a future reader will understand it. Small changes are reviewed far more thoroughly than very large ones.

The software development lifecycle

The software development lifecycle describes the stages a piece of software passes through: understanding requirements, design, building, testing, release and ongoing maintenance. Two broad approaches organise these stages differently.

AspectSequential (often called waterfall)Iterative (often called agile)
PlanningDetailed requirements agreed at the startHigh-level goals, refined as work proceeds
DeliveryOne large release near the endSmall working increments every few weeks
ChangeExpensive once the design is fixedExpected and planned for
SuitsStable, well-understood or highly regulated requirementsUncertain requirements where feedback is valuable

Agile approaches such as Scrum organise work into short cycles called sprints, with regular planning, review and reflection meetings. Kanban visualises work on a board and limits how much is in progress at once. Many organisations use a hybrid, and the labels matter less than the habits: frequent delivery, close contact with users and regular reflection on how to improve.

Continuous integration and delivery

Modern teams automate much of the path from code to release. In continuous integration (CI), every change is automatically built and tested as soon as it is shared, so problems are found within minutes. Continuous delivery (CD) extends this so that software is always in a releasable state, and releases become routine rather than stressful events. The combination of development and operations practices that supports this is often called DevOps.

Environments

Software usually moves through several environments: a developer's own machine, a shared test environment, sometimes a staging environment that closely copies the live system, and finally production, the live system used by real customers. Testing in production-like conditions before release, and never experimenting directly on production data, prevents many incidents.

Common mistakes

  • Keeping important code only on one person's laptop, without version control.
  • Making large changes that are hard to review instead of small, frequent ones.
  • Treating "agile" as a reason to skip documentation, testing or planning altogether.

In practice

Version control is useful beyond code. Teams use the same tools for documentation, configuration files and data analysis scripts. If you work with developers, learning to read a pull request and its discussion will help you follow what is changing and why.

5.3 Security, ethics and your next steps

Software now shapes almost every part of life, from banking and healthcare to transport and public services. This brings responsibility. Computer scientists and anyone who builds or commissions software need to think about security, about the effects of their systems on people and about continuing to learn in a fast-moving field.

Secure by design

Security cannot be added effectively at the end of a project. It must be considered from the start, an approach often called secure by design. Core principles include:

  • Least privilege: every user, program and service should have only the access it needs.
  • Defence in depth: use several layers of protection so that one failure does not expose everything.
  • Validate all input: treat data from users, files and other systems as untrusted until checked. Many attacks, including SQL injection, exploit programs that trust input blindly.
  • Keep secrets out of code: passwords and keys should never be written into source code or committed to version control.
  • Keep dependencies updated: most software relies on many third-party libraries, and known vulnerabilities in them are a common route for attacks.

Passwords should never be stored in readable form. Systems store a hash, the output of a one-way function, created with algorithms designed specifically for passwords. When a user logs in, the system hashes what they type and compares the results. Encryption, by contrast, is reversible with the right key, and is used to protect data in storage and in transit, for example in the secure connections indicated by HTTPS in web addresses.

Tip: Ask "what could go wrong, and who might try to make it go wrong?" at the design stage. This simple habit, known as threat modelling, catches many problems while they are still cheap to fix.

Ethics and social impact

Software decisions can affect people's access to jobs, credit, housing, healthcare and public services. Ethical questions that computer professionals increasingly consider include:

  • Privacy: collecting only the personal data that is needed, being open about its use, and respecting data protection laws such as the GDPR where they apply.
  • Fairness: checking whether automated decisions treat different groups of people unfairly, especially where systems learn from historical data.
  • Accessibility: designing software that works for people with disabilities, for example by supporting screen readers and keyboard navigation. Widely used guidelines such as the Web Content Accessibility Guidelines (WCAG) help.
  • Reliability and safety: recognising that failures in some systems can cause real harm, and testing accordingly.
  • Environmental impact: considering the energy used by large computing workloads and data centres.

Professional bodies for computing in many countries publish codes of conduct covering these themes, and they are worth reading even if you never join one.

Where computer science goes next

Computer science branches into many specialisms, including software engineering, data science and machine learning, cyber security, networks and cloud computing, human-computer interaction, computer graphics and theoretical computer science. The ideas from this course, such as data representation, algorithms, data structures and design principles, underpin all of them.

Building your skills

If you want to continue, a practical learning plan might include:

  1. Choose one beginner-friendly language, such as Python, and stay with it until you are comfortable.
  2. Build small, real projects that solve problems you actually have, such as tidying files, analysing a spreadsheet or creating a simple web page.
  3. Learn SQL alongside your first language, because data skills are useful in almost every role.
  4. Use version control from the start, even for personal projects.
  5. Read other people's code and documentation, and ask questions in learning communities.
  6. Revisit fundamentals, such as algorithms and data structures, once you have some practical experience, because they make more sense then.

Regular short practice is more effective than occasional long sessions. Expect frustration: being stuck is a normal part of programming, not a sign that you lack ability.

In practice

Whatever your role, you can apply this course straight away. Ask suppliers and teams about security, accessibility and data handling. Write clear, step-by-step requirements. Use structured thinking to break down problems. Computer science is ultimately a way of thinking precisely about information and processes, and that skill is valuable in any organisation.

Case study: Paying down technical debt at a ticketing start-up

Quayside Tickets, a fictional small company selling tickets for local theatres, had grown quickly. Its booking system had been written in a hurry by two founders, and pricing rules were copied into the web shop, the box-office screen and the refunds process. Each new discount took weeks to add, and changes often broke something elsewhere.

The new technical lead proposed spending one sprint in three on improvements rather than new features. The team first wrote automated tests around existing pricing behaviour so they would notice any accidental change. They then moved all pricing logic into a single module with a clear interface, used by every part of the system.

They also moved the code into a proper version control repository with required code review, set up continuous integration so tests ran on every change, and removed a database password that had been written into the source code. Within a few months, adding a new discount took days rather than weeks, and the number of pricing errors reported by theatres fell markedly.

Activity

Think of a piece of software you use regularly at work. Describe two features you suspect are designed well and one that seems fragile or hard to change, explaining your reasoning using ideas from this unit such as modularity, duplication or technical debt. Then write three questions you would ask the team responsible to understand its security and maintainability.

Compare with a model answer

A strong answer refers to observable behaviour. For example, it might note that a customer relationship system lets administrators add new fields without code changes, suggesting good abstraction, and that the same login works across several modules, suggesting a shared, well-separated authentication service. It might then point out that discounts are applied differently in quotes and invoices, suggesting duplicated logic that is drifting apart, a sign of technical debt.

The questions are specific and useful, such as: How are changes reviewed and tested before release? How are third-party components kept up to date and monitored for vulnerabilities? Who has access to customer data, and how is it encrypted? The best answers also ask how the team records and prioritises technical debt.

Key takeaways

  • Good software design uses abstraction, modularity, high cohesion and low coupling so that systems remain understandable and safe to change.
  • Technical debt is the future cost of shortcuts; refactoring supported by tests is the main way to reduce it.
  • Version control, code review and continuous integration let teams collaborate safely and release frequently.
  • Security must be designed in from the start, using least privilege, input validation, safe handling of secrets and updated dependencies.
  • Ethical computing considers privacy, fairness, accessibility, reliability and environmental impact.

Unit check

Create a free account to answer the check, save your progress and receive your free certificate.

Create a free account Log in
← Unit 4
WhatsApp