As I understand it, all abstract functions also default to public, and although it is definitely good practice to put in the
public, it's not a requirement to make the abstract class work well. The most perplexing part of abstracts, and interfaces while we're at it, were that they didn't really add anything to make my code work. After all, I could omit the abstract class, and my other classes that once inherited the abstract class, would still work perfectly fine.
However, and here is the really big
however, since I've started to code with abiding by standards, you will realise that entering into an agreement with PHP is a big must, especially if it's not only you who's going to be editing the code. For instance, in programming there are million and one various ways to do the same task. There's a good chance that if you let someone loose on your code with a task in mind, they'd implement it in a only totally different way to which you have. Thus, when you enter into an agreement with PHP, everybody else who comes along must also enter into that agreement with PHP - there's no two ways about it! So if I am creating my child classes which hand out drinks to my PHP code
(lucky PHP code!) then I can tell
everybody who works on my code, to implement the
giveDrink function, like so:
php Code:
abstract public function giveDrink($szDrink);
That way there are no arguments as to how something should be implemented, you've defined the rounds and everybody must abide by that, otherwise you get anarchy, and as I'm sure you're well aware, pure chaos isn't too far behind.
Essentially, you define the rules and everybody must stick to those rules. Great article, Sketch! I just felt it was necessary to cover the reasons why you would use it, I'm sure many are looking over this and thinking,
pfft, I don't need that! Well, you will soon :) If you stick with your programming, I can assure you!