← Back to Dashboard

Object Oriented Programming: Hard Exercises HARD

"""
Topic 07: Object Oriented Programming (OOP) - HARD Exercises (10)
"""

# Exercise 1: Abstract Base Classes - Use the 'abc' module to create an abstract class 'Shape' 
# with an abstract method 'area'. Implement it in 'Square' and 'Triangle'.
# Write your code below:


# Exercise 2: Multiple Inheritance - Create classes 'Flier' and 'Swimmer'. 
# Create a class 'Duck' that inherits from both. Handle any potential conflicts.
# Write your code below:


# Exercise 3: Singleton Pattern - Implement a class 'DatabaseConnection' such that only one 
# instance of the class can ever exist.
# Write your code below:


# Exercise 4: Composition - Create a class 'Engine' and a class 'Car'. 
# The Car should have an Engine object as an attribute.
# Write your code below:


# Exercise 5: Operator Overloading - Create a class 'Matrix' (2x2) and overload the '*' operator 
# to perform matrix multiplication.
# Write your code below:


# Exercise 6: Decorators on Methods - Write a decorator that logs every time a method of a class is called.
# Write your code below:


# Exercise 7: Custom Iterator - Create a class 'Countdown' that acts as an iterator, 
# counting down from a given number to zero.
# Write your code below:


# Exercise 8: Method Resolution Order (MRO) - Create a complex inheritance structure (Diamond Problem) 
# and use help() or .mro() to demonstrate how Python finds methods.
# Write your code below:


# Exercise 9: Data Classes - Use the @dataclass decorator from 'dataclasses' module 
# to create a simple 'Product' class. Explain its benefits.
# Write your code below:


# Exercise 10: Mini Project - Implement a "School Management System" using OOP. 
# Include classes for Person, Teacher, Student, and Course. 
# Demonstrate inheritance, relationship (composition), and polymorphism.
# Write your code below: