Official government website of the Government of Kingdom of Saudi Arabia
Link to official Saudi websites end with edu.sa

All links to official educational websites in the Kingdom of Saudi Arabia end with sch.sa or edu.sa

Government websites use the HTTPS protocol for encryption and security.

Secure websites in the Kingdom of Saudi Arabia use the HTTPS protocol for encryption.

Registered with the Digital Government Authority under number:

20250417892

Object oriented programming with Python

CS1012
3 hours English

Object oriented programming with Python

Object Oriented Programming in Python
1 Introduction to Object-Oriented Programming: / What is Object-Oriented Programming (OOP)? / Benefits of OOP: modularity, code reuse, and maintainability / Introduction to classes and objects / How Python supports OOP / Writing simple classes and creating objects / Lab: / Create a simple Python class (e.g., a `Book` class with attributes like `title`, `author`, and `year`) / Instantiate objects and access their attributes and methods
2 Attributes and Methods: / Instance attributes vs class attributes / Methods: defining and calling methods inside classes / The `self` keyword in Python / Introduction to the `__init__()` constructor method / Lab: / Implement a class with instance and class attributes (e.g., a `Car` class with attributes like `make`, `model`, and `year`) / Create methods to perform actions on object attributes (e.g., a `start_engine()` method)
3 Encapsulation Private and Public Attributes: / Encapsulation in OOP: hiding internal details and exposing only necessary parts / Public vs private attributes and methods / Using the `__` (double underscore) to make attributes private / Getter and setter methods / Lab: / Implement a class with private and public attributes (e.g., a `BankAccount` class where the balance is private) / Use getter and setter methods to access and modify private attributes
4 Inheritance and Extending Classes: / Introduction to inheritance and its advantages (code reuse) / Defining a subclass: syntax and usage / Using the `super()` function to call methods from the parent class / Overriding methods in subclasses / Lab: / Create a subclass that inherits from a parent class (e.g., a `Dog` class inheriting from an `Animal` class) / Overriding methods to change or extend functionality
5 Polymorphism and Method Overriding: / What is polymorphism? The ability to use the same method name with different behaviors / Method overriding vs method overloading / Using polymorphism in Python through method overriding / Duck typing in Python (dynamic typing) / Lab: / Create multiple subclasses (e.g., `Cat`, `Dog`) and override the `speak()` method from a base class `Animal` / Demonstrate polymorphism by calling the same method on different object types
6 Abstraction Abstract Classes and Methods: / What is abstraction? Hiding implementation details and showing only essential features / Abstract base classes (ABC) in Python using the `abc` module / Defining abstract methods / The difference between abstract and concrete classes / Lab: / Create an abstract base class for different shapes (e.g., `Shape`) and implement specific subclasses (e.g., `Circle`, `Rectangle`) / Define abstract methods like `area()` and `perimeter()` that must be implemented by each subclass
7 Class and Static Methods: / Understanding the difference between instance methods, class methods, and static methods / Class methods: the `@classmethod` decorator, `cls` parameter / Static methods: the `@staticmethod` decorator / When to use class methods and static methods / Lab: / Implement class methods to modify class-level attributes / Implement static methods to perform utility tasks not dependent on class or instance data
8 Composition vs Inheritance: / Composition vs Inheritance: when to prefer one over the other / Composition: using objects of other classes as attributes / Advantages of composition in certain designs (e.g., flexibility and loose coupling) / Lab: / Implement composition in Python by creating classes that contain instances of other classes as attributes (e.g., a `Library` class containing `Book` objects) / Compare the design to one using inheritance and discuss the pros/cons
9 Multiple Inheritance and the MRO (Method Resolution Order): / What is multiple inheritance? Inheriting from more than one parent class / The Method Resolution Order (MRO) in Python and how it determines the order of method calls in multiple inheritance / The `mro()` function and the `super()` function in multiple inheritance / Lab: / Create a class that inherits from two parent classes (e.g., a `FlyingCar` class that inherits from both `Car` and `Airplane`) / Explore the MRO and how Python resolves method calls in multiple inheritance scenarios
10 Special Methods and Magic Methods: / Introduction to magic methods (also known as dunder methods): `__init__()`, `__str__()`, `__repr__()`, `__eq__()`, `__add__()`, etc. / Overloading operators with magic methods / The importance of `__str__()` and `__repr__()` for object representation / Lab: / Implement `__str__()` and `__repr__()` for custom classes / Overload comparison (`__eq__()`) and arithmetic (`__add__()`) operators in a custom class (e.g., `Point` class for 2D vectors)
11 Error Handling and Custom Exceptions: / Handling errors in Python with `try`, `except`, `else`, and `finally` / Creating custom exceptions by subclassing the `Exception` class / Raising exceptions with the `raise` keyword / Lab: / Write custom exception classes (e.g., `InvalidAgeError`, `InsufficientFundsError`) / Implement error handling in a class that interacts with user inputs or external resources (e.g., a `Transaction` class)
12 Design PatternsSingleton and Factory Patterns: / Introduction to design patterns in OOP / The Singleton pattern: ensuring a class has only one instance / The Factory pattern: creating objects without specifying the exact class / Lab: / Implement the Singleton pattern in Python using a class method or metaclass / Create a Factory pattern for generating different types of objects (e.g., `ShapeFactory` to create different shapes)
13 Introduction to Unit Testing with OOP: / The importance of unit testing in OOP / Using Python's `unittest` module for testing classes and methods / Writing test cases for methods in your classes / Lab: / Write unit tests for custom classes using the `unittest` framework / Implement test-driven development (TDD) by creating tests for class methods and attributes
14 Working with External Libraries (like `requests`, `matplotlib`): / How to integrate third-party libraries into your OOP designs / Using external libraries in Python for web requests, data visualization, etc. / Best practices for writing modular, testable code / Lab: / Build a small application (e.g., a weather application that uses the `requests` library to get data from an API) / Integrate libraries such as `matplotlib` or `Pandas` into an OOP design for data analysis or visualization
15 Final Project and Course Review: / Review of all OOP concepts covered: classes, inheritance, polymorphism, abstraction, and error handling / Best practices for writing maintainable and scalable Python code / Project design considerations and OOP principles in real-world scenarios / Lab: / Final Project: Develop a Python application that applies object-oriented programming concepts (e.g., a simple simulation, inventory system, or mini game) / Peer review of final projects
1.1 Mapped to: K1

Understand the core principles of Object-Oriented Programming (OOP), including encapsulation, inheritance, polymorphism, and abstraction, and their role in designing robust and maintainable Python programs.

Teaching Strategy Lectures, lab sessions, guided discussions
Assessment Methods Quizzes, midterm exam, final exam
1.2 Mapped to: K1, K2

Explain the structure and design of modular and reusable Python programs by defining and using classes, objects, and design patterns.

Teaching Strategy Lectures, lab sessions, case studies
Assessment Methods Homework assignments, quizzes, final exam
1.3 Mapped to: K3

Explain error handling strategies using custom exceptions and unit testing to ensure the reliability of Python applications.

Teaching Strategy Lectures, practical lab exercises, project-based learning
Assessment Methods Homework assignments, lab project, final exam
2.1 Mapped to: S1

Design and implement Python programs using Object-Oriented Programming concepts such as encapsulation, inheritance, polymorphism, and abstraction to solve computational problems.

Teaching Strategy Lab sessions, hands-on coding exercises, project-based learning
Assessment Methods Lab exercises, lab project, midterm exam
2.2 Mapped to: S2

Develop modular, reusable, and maintainable code by utilizing classes, objects, and design patterns effectively in Python projects.

Teaching Strategy Lab sessions, project-based learning, problem-solving workshops
Assessment Methods Lab project, homework assignments
2.3 Mapped to: S5

Write and execute unit tests to verify program functionality and manage errors using custom exceptions for robust Python applications.

Teaching Strategy Lab sessions, practical exercises, project-based learning
Assessment Methods Lab project, quizzes, homework assignments
3.1 Mapped to: V1

Demonstrate ethical responsibility in designing and sharing Python programs by adhering to best practices in coding, debugging, and documentation.

Teaching Strategy Lectures on coding ethics, reflective discussions, project work
Assessment Methods Lab project, homework assignments
3.2 Mapped to: V3

Engage in self-directed learning to explore advanced OOP techniques and external libraries, fostering a commitment to continuous professional development.

Teaching Strategy self-paced assignments, project-based learning
Assessment Methods Lab project, homework assignments
3.3 Mapped to: V2

Collaborate effectively within a team to design and implement Python-based OOP projects, demonstrating leadership and respect for diverse perspectives.

Teaching Strategy Team-based lab sessions, collaborative projects, peer feedback
Assessment Methods Lab project, peer evaluation, final presentation