Untitled
<?php class MySQLDatabase { public function saveOrder($order) { // Logic to save the order in MySQL database echo "Saving order to MySQL database.\n"; } } class OrderService { private $db; public function __construct() { $this->db = new MySQLDatabase(); // Direct dependency on a specific implementation } public function placeOrder($order) { // Some logic for placing the order $this->db->saveOrder($order); } } // Usage $orderService = new OrderService(); $orderService->placeOrder('Order 1');
Leave a Comment