WK3: Comparing Procedural and Object-Oriented Paradigms with Hands-on Exercises (Session 2)

Welcome
Comparing Procedural and 
Object-Oriented Paradigms with Hands-on Exercises
Module Lecturer: Dr Raghav Kovvuri
Email: raghav.kovvuri@ieg.ac.uk

Week 3
1 / 7
next
Slide 1: Slide
ProgrammingHigher Education (degree)

This lesson contains 7 slide, with text slide.

Items in this lesson

Welcome
Comparing Procedural and 
Object-Oriented Paradigms with Hands-on Exercises
Module Lecturer: Dr Raghav Kovvuri
Email: raghav.kovvuri@ieg.ac.uk

Week 3

Slide 1 - Slide

Recap-Procedural Programming
Definition: A programming paradigm based on the concept of procedure calls. It structures code into procedures (also known as routines, subroutines, or functions) that operate on data.
Emphasis on Procedures:
Top-down Approach:
Separation of Data and Procedures
  • Programs are structured as a sequence of procedures.
  • Each procedure contains a series of computational steps to be carried out. 
  • Problems are broken down into smaller, manageable procedures.
  • Program design starts with defining high-level steps, then breaking these down into more detailed sub-steps.
  • Data structures and procedures that operate on them are separate entities.
  • Global data can be accessed and modified by any procedure.

Slide 2 - Slide

Recap-Object-Oriented Programming (OOP)
Definition: A programming paradigm based on the concept of "objects," which can contain data and code. The data is in the form of fields (attributes), and the code is in the form of procedures (methods).
Emphasis on Objects:
Bundling of Data and Methods:
OOP Concepts:
  • Programs are structured as collections of objects.
  • Objects contain both data (attributes) and methods that operate on that data.
  • Data and the methods that operate on that data are encapsulated within objects.
  • This bundling helps in achieving data hiding and abstraction.
  • Encapsulation: Bundling of data and methods that operate on that data.
  • Inheritance: Ability to create new classes based on existing classes.
  • Polymorphism: Ability of different classes to be treated as instances of the same class through inheritance.

Slide 3 - Slide

Comparative Analysis
  • Download the table provided in Canvas which provides a concise, side-by-side comparison of Procedural and Object-Oriented Programming across various aspects.
*Remember, while this table provides a good overview, it's important to emphasize that the choice between procedural and OOP often depends on the specific requirements of a project. 

Slide 4 - Slide

Hands-on Exercise
Task: Convert a procedural program to an object-oriented design
  • Simple Calculator.py
Instructions for students:


  • Implement the Calculator class with methods for each operation.
  • Move the main loop into the run method of the Calculator class.
  • Encapsulate the operation logic within the class.
  • Consider how to handle the menu display and user input in an OOP way.
timer
40:00
  • Implement on WK3_Conversion.py (Download from Canvas)

Slide 5 - Slide

Exercise - Library Management System
Task: Create a simple library management system using OOP principles
Requirements:
  • Create the following classes: 
  • Book: Attributes for title, author, ISBN, and availability
  • Library: Manages a collection of books
  • Member: Represents library members who can borrow books


  • Implement methods for:
  • Adding and removing books from the library
  • Checking out and returning books
  • Displaying available books
  • Registering new members


  • Use inheritance to create different types of books (e.g., Fiction, NonFiction)
  • Implement encapsulation for member details and book availability
  • Use polymorphism to handle different types of books

Slide 6 - Slide

Slide 7 - Slide