0

I am creating an invoice management system that has a User Class that handles the login system.

Currently each User is associated with a Customer and the Customer class handles obtaining Monthly Invoices.

My problem is that some Users are Business Owners and would like to be able to see all of their Invoices through one log in instead of having multiple.

If my current Customer has these properties

class Customer {

private $f_name;
private $l_name;
private $address_1;
private $address_2;
private $zip;
private $state;
private $phoneNumber;
private $email;
private $registrationDate;
private $user_id;
private $customer_id;

Would I make a subclass of Business? And How would I handle options like f_name and l_name because each business wouldn't have a f_name or l_name it would just be a business name.

Or each User could associate with a Business and/or Standard Customer and each have their own class?

I don't know why this concept is confusing me this much.

  • I don't think I understood your question fully. What I got is that you want to have customers who could play multiple roles? Maybe add user_type? – Mohammed Joraid Mar 25 '18 at 17:35
2

I’m not sure why both business owner customers and customers wouldn’t be able to see their invoices after a single login?

The way I see it, all business owners would be a type of customer. Also you would probably want to know a contact person behind the business, not necessarily just the business name. Although, if you didn’t not want to have a f_name and l_name for business owners, you could just leave that field blank. You may want to be able to set a f_name and l_name in the future.

It may be worth also having an abstract Customer class to base all your Customer types off of. It makes your code more polymorphic. It’s better to rely on abstractions than concretions.

abstract class Customer {
 //using protected instead of private so child classes have access to the properties
 protected $f_name;
 protected $l_name;
 //etc...
}
class SimpleCustomer extends Customer {}
class BusinessCustomer extends Customer {
 public function __construct(){
  parent::__construct(); //calls to the parent Customer class’s construction
  //May want to pass args if Customer requires them
  //This is only necessary if BusinessCustomer does anything unique in its construction compared to in it’s parent class
 }
 public function setBusinessName(String $b_name) {
  $this->business_name = $b_name;
 }
}

Essentially, as you mentioned, each would have its own class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.