A
A
Anonymous859662020-08-26 16:19:10
PHP
Anonymous85966, 2020-08-26 16:19:10

Is it acceptable to use inheritance in this situation?

There are two classes for the online store. The first class is called User. It contains variables and methods for defining email, user ID, and so on. The second class is called basket. It contains methods for removing items from the cart, adding items to the cart, and so on. In the basket class, the function for displaying goods from the database takes a user ID as an argument, which is written to the sql query. The user ID can be obtained from a method in the User class. Therefore, I implemented class Basket extends User inheritance. A constructor is created in it, in which variables are written from class User parent::__construct($email, $password). Is it acceptable to use inheritance in this situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lazy @BojackHorseman PHP, 2020-08-26
@Anonymous85966

if it seems natural to you that the basket and the user are relatives, then you can.

T
Tendor, 2020-08-26
@Tendor

I think the user should have a getBasket () method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question