This project is a clean and extensible product management system built using Object-Oriented PHP. It demonstrates professional software design principles such as abstraction, inheritance, encapsulation, and polymorphism, while adhering to PSR-4 standards and Composer-based autoloading.
Designed as a practical example, this project focuses on how to structure and scale PHP applications without frameworks — keeping the architecture lightweight, modular, and easy to extend.
Abstract base class for unified product structure.
- Type-specific product classes (Book, DVD, Furniture) extending shared logic.
- Dynamic class loading for different product types (no if/else or switch statements).
- Encapsulated data management via getters and setters.
- Single endpoint for all product operations.
- PSR-4 autoloading using Composer.
- Pure PHP 7+ implementation - no frameworks, just clean OOP.
/src
/Models
Product.php
Book.php
DVD.php
Furniture.php
/Database
Database.php
index.php
composer.json
README.md
- Language: PHP 7.0+
- Database: MySQL
- Architecture: Object-Oriented (no frameworks)
- Autoloading: Composer (PSR-4)
- Environment: Independent, lightweight, and framework-free
Client sends a POST request to a single endpoint (index.php).
- The system dynamically maps the type (e.g., Book, DVD, Furniture) to its corresponding class using namespaces and autoloading.
- The product instance handles its own logic via polymorphism — no conditionals required.
- The Database class saves data through object properties using getters/setters.
- The result is a clean, extensible architecture that scales easily as new product types are added.
CREATE DATABASE IF NOT EXISTS products_db;
USE products_db;
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
sku VARCHAR(64) NOT NULL UNIQUE,
name VARCHAR(255) NOT NULL,
price DECIMAL(10,2) NOT NULL,
attribute VARCHAR(255) NOT NULL,
height DECIMAL(10,2) NULL,
width DECIMAL(10,2) NULL,
length DECIMAL(10,2) NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
git clone https://github.com/lokeshrangani/product-oop-example.git
cd product-oop-example
composer dump-autoload
php -S localhost:8000
POST http://localhost:8000/index.php
{
"type": "book",
"sku": "BK001",
"name": "Object-Oriented PHP",
"price": "19.99",
"attribute": "1.2"
}This project is a practical showcase of:
- Clean OOP architecture in PHP
- Polymorphism and abstraction in action
- Eliminating conditional branching with class inheritance
- PSR-4–compliant project structure
- Database encapsulation using object properties
- Add data validation and error handling.
- Mass deleting
- Update
Open source and free to use for educational or portfolio purposes. You are welcome to clone, modify, and build upon it.
An experienced PHP developer with a deep interest in Object-Oriented architecture, scalable backend systems, and clean code principles. Skilled in designing maintainable solutions that follow SOLID and PSR standards, with a focus on practical implementation, performance, and clarity. Believes that good code should be self-explanatory, adaptable, and built to last.
LinkedIn: linkedin.com/in/lokeshrangani