PHP: If I have a customer class, and the customer can have a car and an invoice, and I want to have separate car and invoice classes, what is the most efficient way of setting them up?
So, I have three different classes:
customer.class.php
customer_car.class.php
customer_invoice.class.php
What’s the best way to set up the relationship/initialization between the three classes? A customer can have a car or an invoice. I want to keep the code separated so that its easy to maintain.
$customer = new customer();
$car = $customer->newCar();
$invoice = $customer->newInvoice();
?
Here is just an idea as it may be structure differently to reflect your business logics…
Have 3 seperate classes
customer,carandinvoice.Customerscan can zero to manycarsto them.Customercan have zero to manyinvoicesto them.An
invoicemay belong to 1 and only 1customerand able to have 1 to manycars.Illustration of a customer class:
Illustration of usage:
Note: Illustration code is in PHP4, where you may feel free (also recommanded) to develop with PHP5 syntax.