0% found this document useful (0 votes)
16 views

Object Oriented Programming (OOP)

Uploaded by

hadiyahaya87
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Object Oriented Programming (OOP)

Uploaded by

hadiyahaya87
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Object Oriented Programming

Scheme of work
Week 1: Introduction to Programming Paradigms & OOP Concepts

 Topic: Overview of programming paradigms (procedural, functional, object-


oriented)
 Key Concepts:
o Introduction to OOP
o Why OOP? (Benefits and applications)
o Real-world analogies of OOP
 Activities:
o Discussion on common programming paradigms
o Setting up the development environment (choose a language: Python, Java,
C++, etc.)
 Assignment: Simple procedural programs to contrast with OOP structure.

Week 2: Classes and Objects

 Topic: Defining and using classes and objects


 Key Concepts:
o What are classes and objects?
o Creating classes and instantiating objects
o Attributes and methods (instance variables and functions)
 Practical:
o Write basic programs defining simple classes like Car, Animal, etc.
o Object instantiation and calling methods.
 Assignment: Create a class for a real-world entity with attributes and methods.

Week 3: Encapsulation and Abstraction

 Topic: Data hiding and simplifying complexity


 Key Concepts:
o Encapsulation: private vs public attributes
o Getters and setters
o Abstraction: hiding internal complexity
 Practical:
o Modify previous classes to use encapsulation
o Write programs demonstrating encapsulation (e.g., banking system with
account balance).
 Assignment: Implement encapsulation in your class, protect sensitive data.

Week 4: Constructors and Destructors

 Topic: Object lifecycle


 Key Concepts:
o Constructors: __init__ (in Python) or constructors in other languages
o Parameterized constructors
o Destructors (optional in some languages)
 Practical:
o Create a class that uses constructors for initialization.
o Examples like user profile creation, product creation, etc.
 Assignment: Create a class that requires initialization with parameters (e.g., Book
with title, author, year).

Week 5: Inheritance

 Topic: Extending classes


 Key Concepts:
o Concept of inheritance (base and derived classes)
o Single inheritance
o super() function to call base class constructors/methods
 Practical:
o Create base and derived classes (e.g., Animal -> Dog, Cat)
o Override methods in derived classes.
 Assignment: Build a system with inheritance (e.g., vehicle hierarchy).

Week 6: Polymorphism

 Topic: Multiple forms of methods


 Key Concepts:
o Method overloading (if applicable in chosen language)
o Method overriding
o Polymorphic behavior in OOP
 Practical:
o Implement method overriding in derived classes.
o Demonstrate polymorphism through function calls.
 Assignment: Write polymorphic programs that use the same method in different
ways.

Week 7: Interfaces and Abstract Classes (optional for some languages)

 Topic: Abstract methods and enforcing structure


 Key Concepts:
o Abstract classes and methods
o Interfaces (language-specific: e.g., in Java, C++)
o Difference between abstract classes and interfaces
 Practical:
o Implement abstract classes or interfaces.
o Example: a Shape class with abstract methods for calculating area and
perimeter.
 Assignment: Create an abstract class and extend it in concrete classes.

Week 8: Composition and Aggregation

 Topic: Object relationships


 Key Concepts:
o Composition: "Has-a" relationship
o Aggregation
o Difference between inheritance and composition
 Practical:
o Create a class that has objects of other classes (e.g., Car with Engine,
Wheel).
 Assignment: Design a system that uses composition (e.g., school system with
classes and students).

Week 9: Exception Handling in OOP

 Topic: Error handling in OOP


 Key Concepts:
o Exception handling: try, except (Python) or try, catch (Java, C++)
o Raising exceptions in methods
o Custom exceptions
 Practical:
o Implement basic error handling in class methods.
o Create and raise custom exceptions.
 Assignment: Modify a previous class to handle invalid inputs using exceptions.

Week 10: File Handling in OOP

 Topic: Saving and loading data in object-oriented programs


 Key Concepts:
o Reading from and writing to files
o Using classes to structure file input/output
o Serialization (e.g., using pickle in Python)
 Practical:
o Implement file handling within a class (e.g., saving and loading user data).
 Assignment: Create a class that writes to and reads from a file.

Week 11: Advanced OOP Concepts

 Topic: Design patterns, decorators, or multiple inheritance


 Key Concepts (choose based on course level):
o Design patterns (e.g., Singleton, Factory, Observer)
o Multiple inheritance (optional)
o Decorators in Python
 Practical:
o Implement an example of a design pattern or multiple inheritance.
 Assignment: Research and implement a common design pattern in a project.

Week 12: OOP Project & Review

 Topic: Final project and review of key OOP concepts


 Key Concepts:
o Integrating OOP concepts into a complete project
o Reviewing inheritance, polymorphism, and other core ideas
 Practical:
o Start a final project that incorporates everything learned.
o Example projects: inventory management system, library system, etc.
 Assignment: Submit the final project for grading.

Assessment and Evaluation:

 Quizzes: Weekly quizzes to test understanding of key concepts.


 Assignments: Regular assignments based on weekly topics.
 Final Project: A complete object-oriented project that demonstrates proficiency.

This scheme provides a structured approach to learning OOP, combining theoretical


understanding with hands-on programming experience.

Notes
Week 1: Introduction to Programming Paradigms & OOP Concepts

1. Programming Paradigms Overview:

 Procedural Programming: Focuses on functions and the sequence of tasks to


accomplish. E.g., C.
 Object-Oriented Programming (OOP): Organizes software design around data, or
objects, rather than functions and logic.
 Functional Programming: Emphasizes the use of functions and immutability. E.g.,
Haskell, Python (partly).

2. Why OOP?

 OOP simplifies complex software design by using real-world analogies (like objects,
which represent things like cars or users).
 Encourages reusability, modularity, and maintainability of code.

3. Key Concepts in OOP:

 Class: A blueprint for creating objects (e.g., a blueprint for cars).


 Object: An instance of a class (e.g., a specific car).
 Attributes: Characteristics or properties of an object (e.g., color, brand).
 Methods: Functions inside classes that define behaviors (e.g., start, stop).
Week 2: Classes and Objects

1. What is a Class?

 A class defines a type of object, acting as a template for creating objects.


 Example in Python:

python
Copy code
class Car:
def __init__(self, brand, color):
self.brand = brand
self.color = color

def start(self):
print(f"The {self.color} {self.brand} car is starting.")

2. What is an Object?

 An object is an instance of a class:

python
Copy code
my_car = Car("Toyota", "red")
my_car.start()

3. Attributes and Methods:

 Attributes: Data stored in an object (e.g., brand, color).


 Methods: Functions that perform operations (e.g., start()).

Week 3: Encapsulation and Abstraction

1. Encapsulation: #think of it like a capsule to keep objects from people

 Encapsulation is about restricting direct access to some of an object’s components and


methods. You can make variables private using underscores in Python.
 Example:

python
Copy code
class BankAccount:
def __init__(self, balance):
self.__balance = balance # private variable

def get_balance(self):
return self.__balance

def deposit(self, amount):


self.__balance += amount

2. Abstraction: #think of it like art just appreciate it rather than knowing its purpose

 Abstraction hides the complex implementation details and shows only the necessary
parts.
 Example: You don’t need to know the internals of how a start() method works, just
how to use it.

Week 4: Constructors and Destructors

1. Constructors (__init__): #quick reminder there are double underscores

 Constructors are special methods used to initialize objects when they are created.
 Example:

python
Copy code
class Person:
def __init__(self, name, age):
self.name = name
self.age = age

2. Destructors:

 Destructors (optional in most modern programming) clean up when an object is no longer


needed.
 In Python, the destructor is __del__, but it is rarely used explicitly.

Week 5: Inheritance

1. Inheritance Basics: #think of it like genes that are passed to offsprings

 Inheritance allows one class (derived/child class) to inherit attributes and methods from
another class (base/parent class).
 Example:

python
Copy code
class Animal:
def sound(self):
print("This animal makes a sound.")
class Dog(Animal):
def sound(self):
print("The dog barks.")

2. Overriding Methods:

 The Dog class can override the sound method from the Animal class to give its own
specific behavior.
 Example:

python
Copy code
my_dog = Dog()
my_dog.sound() # Output: "The dog barks."

Week 6: Polymorphism

1. Polymorphism Definition:

 Polymorphism allows methods to do different things based on the object calling them,
even though the method name remains the same.

2. Method Overloading (Not in Python, but in Java/C++):

 Overloading allows creating multiple methods with the same name but different
parameters. Not directly supported in Python.

3. Method Overriding (Python Example):

 You can override methods from a parent class in the child class.
 Example:

python
Copy code
class Bird:
def fly(self):
print("The bird flies.")

class Penguin(Bird):
def fly(self):
print("Penguins can't fly!")

Week 7: Interfaces and Abstract Classes

1. Abstract Classes:
 Abstract classes cannot be instantiated directly and must be inherited by subclasses.
 Example:

python
Copy code
from abc import ABC, abstractmethod

class Shape(ABC):
@abstractmethod
def area(self):
pass

2. Interfaces (in languages like Java/C++):

 An interface defines a set of methods that must be implemented by any class that
"implements" the interface.

Week 8: Composition and Aggregation

1. Composition:

 Composition describes a "has-a" relationship, where an object is composed of other


objects.
 Example:

python
Copy code
class Engine:
def start(self):
print("Engine started")

class Car:
def __init__(self):
self.engine = Engine()

def start_car(self):
self.engine.start()

2. Aggregation:

 Similar to composition, but the lifecycle of the contained objects is not dependent on the
container.

Week 9: Exception Handling in OOP


1. Exception Handling Basics: #in these type of situations use the try , except and finally
functions

 Exceptions handle runtime errors gracefully.


 Example:

python
Copy code
try:
x = int(input("Enter a number: "))
except ValueError:
print("That's not a valid number!")

2. Raising Custom Exceptions:

 You can define and raise custom exceptions in Python.


 Example:

python
Copy code
class NegativeValueError(Exception):
pass

def check_value(value):
if value < 0:
raise NegativeValueError("Value cannot be negative!")

Week 10: File Handling in OOP

1. Reading from and Writing to Files:

 File handling allows you to persist data.


 Example:

python
Copy code
class FileHandler:
def write_to_file(self, filename, data):
with open(filename, 'w') as file:
file.write(data)

def read_from_file(self, filename):


with open(filename, 'r') as file:
return file.read()

2. Serialization (Optional):

 Serialization allows saving and loading objects.


 In Python, pickle is used for serialization.
Week 11: Advanced OOP Concepts

1. Design Patterns (Optional for Advanced Students):

 Singleton: Ensures that a class has only one instance.


 Factory Pattern: Creates objects without exposing the instantiation logic.

2. Multiple Inheritance:

 Python supports multiple inheritance, though it’s not always recommended due to
complexity.
 Example:

python
Copy code
class A:
pass

class B:
pass

class C(A, B):


pass

Week 12: OOP Project & Review

1. Integrating OOP Concepts:

 Final projects typically involve integrating multiple OOP concepts like inheritance,
encapsulation, polymorphism, file handling, and error handling.
 Example projects:
o Inventory System: Managing products with categories and stock levels.
o Library System: Managing books, borrowers, and due dates.

You might also like