Practical 13: Support & Review

CAB201 - Programming Principles

School of Computer Science, Faculty of Science

Review - C# Programming

In this unit, we have learned about C#, a modern, general-purpose, object-oriented programming language developed by Microsoft.

C# uses curly brackets for code blocks and semicolons to terminate statements.

Variables are strongly typed and must be declared before use.

int i;
for (i = 0; i < 10; i++) {
    Console.WriteLine(i);
}
Console.WriteLine($"The final value of i is {i}"); // 10
CAB201 - Programming Principles
School of Computer Science, Faculty of Science

Review - Classes and Objects

In C#, a class is a blueprint for creating objects. An object is an instance of a class.

class Person {
    public string Name { get; }
    public int Age { get; }
    public Person(string name, int age) {
        Name = name;
        Age = age;
    }
}
class Student : Person {
    public string StudentId { get; }
    public Student(
      string name, 
      int age, 
      string studentId) : base(name, age) {
        StudentId = studentId;
    }
}
Person person = new Person("Alice", 30);
// A student is also a person
Person student = new Student("Bob", 20, "s123456");
CAB201 - Programming Principles
School of Computer Science, Faculty of Science

Review - Object-Oriented Programming

The four principles of object-oriented programming are:

  1. Abstraction: Hiding implementation details while exposing a simple interface. Achieved through interfaces, abstract classes, classes and methods.
  2. Encapsulation: Bundling data and methods that operate on that data into a single unit. Usually accompanied by information hiding with access modifiers.
  3. Inheritance: Defining a new class based on an existing class. The new class inherits the properties and methods of the existing class.
  4. Polymorphism: The ability to use a single interface to represent different data types or actions. Achieved through method overloading and overriding.
CAB201 - Programming Principles
School of Computer Science, Faculty of Science

Review - Other concepts

  • Exception handling: Use try, catch, finally blocks to handle exceptions, and throw to raise exceptions.
  • File I/O: Use StreamReader and StreamWriter to read and write (text) files.
  • Delegates: Reference to a method, allowing methods to be passed as parameters.
  • Generics: Placeholder for types, allowing classes and methods to be reused with different data types. Mostly used with collections.
  • Collections: Data structures that hold multiple items. Common collections include List, Dictionary, and HashSet.
  • Unit Testing (with MSTest): Automate testing of individual unit (a single class, or method).
CAB201 - Programming Principles
School of Computer Science, Faculty of Science

Exam Support

Beside the major assignment, there is a final exam for this unit:

  • Combination of multiple choice and written questions.
  • All topics covered in the unit are examinable.
  • Closed book: No notes, textbooks, or electronic devices.
  • Prepare to read and write C# code.

Don't forget to check your exam timetable.

CAB201 - Programming Principles
School of Computer Science, Faculty of Science

Student Voice Survey

A link to the Student Voice Survey is sent to your email, to provide feedback for:

  • The unit as a whole.
  • Your lecturer.
  • Your tutor.

Your feedback is invaluable to ensure the quality of the unit.

CAB201 - Programming Principles
School of Computer Science, Faculty of Science