C
C
cybernoob2018-02-21 16:22:36
PHP
cybernoob, 2018-02-21 16:22:36

Why is it impossible to inherit from the DB class?

Imagine that we have a DB class that works with a database. It has simple and clear CRUD methods.
Why not inherit other classes from it? For example a class of users or a class of articles.
It's very convenient, I can just do it. parent::saveUser();
Can you explain why this is bad practice (but not so "it violates the single responsibility principle" - I myself know this).
And how to correctly determine which class can be inherited from which, and by what signs can you determine what is impossible and this is a bad idea?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-02-21
@cybernoob

Excuse me, I don’t want to offend anyone, but such a desire to inherit from everything and the lack of understanding why this cannot be done indicates a complete misunderstanding of the OOP concept. It is not possible to fully answer your questions - a post is not enough, you can write a whole lecture here. And the answers will only give rise to additional questions. Therefore, it is better to take another week - and read a couple of books on OOP, and immediately everything will fall into place ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question