I'm planning to implement a system with a super class named User and 2 subclasses of the class User, named Seller and Buyer. They are specific types of Users.
So, I have 3 files with 3 classes:
- User.php (class User)
- Seller.php (class Seller extends User)
- Buyer.php (class Buyer extends User)
When there is a session indicating that the user is logged I want to create the corresponding object user type (Seller or Buyer).
My first instinct was to instantiate the User class with the given session ID and then, inside, instantiate the corresponding subtype. But I believe this is extremely incorrect cause I'm trying to instantiate a subclass from the inside of a superclass.
What's the best approach to implement such a system?