OOPatternDetector is a Python utility for detecting object-oriented programming (OOP) patterns, such as abstraction and inheritance in Python code. It analyzes source code and provides insights into the use of OOP principles.
- Detects classes that use abstraction via the
abcmodule. - Detects classes that use the Inheritance pattern.
Clone the repository and install the library locally:
git clone https://github.com/yourusername/oopatterndetector.git
cd oop_pattern_detector
pip install .Install the library directly from GitHub:
pip install git+https://github.com/SE-UoM/python-oop-pattern-finder.gitThe OOPatternDetector class is the main interface for detecting OOP patterns in Python code. You can use it to analyze a Python file or a directory containing Python files.
from oop_pattern_detector import OOPatternDetector
# Load the source code to analyze
source_code = """
from abc import ABC
class AbstractBase(ABC):
pass
class ConcreteClass(AbstractBase):
pass
"""
# Initialize the detector
detector = OOPatternDetector(source_code)
# Analyze the source code
classes = detector.analyze()
# Print class details
for cls in classes:
print(f"Class: {cls.name}, Base Classes: {cls.base_classes}, Uses Abstraction: {cls.uses_abstraction}")