0

what is exact abstract class in php, and the difference between other declaration like static, protected and private?

I knew this is cliche question you could find lots discussion over google, but I would like to know more concrete if there's someone could give the explanation more easily to understand? for example below: abstract class abstract { protected function num() { return 10; } public function add() { return 10 + 10; } } public class public { protected function num() { return 10; } public function add() { return 10 + 10; } } if we called those 2 CLASS: what will be the difference between those? As I found really good explanation here: https://stackoverflow.com/questions/2558559/what-is-abstract-class-in-php An abstract class is a class that is only partially implemented by the programmer. It may contain one or more abstract methods. An abstract method is simply a function definition that serves to tell the programmer that the method must be implemented in a child class. So in this case for real practice, what kind of scenario you use abstract class? thank you so much

8th Jan 2018, 11:53 AM
tess hsu
tess hsu - avatar
1 Odpowiedź
0
abstract classes would be used to define a type of something but not completly defining all the business logic. you cannot create instances of an abstract class, you can only extend them. an example might be if i wanted to have a four classes all of them being user actions. Create, Update, Ban, Activate. all of them could extend an abstract class named UserActions. it may store some common logic for all user actions, and it can require an abstract method like executeAction() which all children would be required to define themselves. you would not be able to directly create an indtance of UserAction but you could with its children.
10th Dec 2018, 3:43 AM
John Anderson
John Anderson  - avatar