Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This will be a simplification, but to give you a real life example:</p> <p>Consider that you were to create a content management system, i.e., a script to show different pages on your website based on user input.</p> <p>You would probably want each page (let's call them modules) to have specific features, such as allowable commands to be executed when on that page/module. These different commands could then be different methods within each module class.</p> <p>However, what if you were to allow a login command, no matter where the user was currently at in your website? i.e., this would be a command shared between all the modules. </p> <p>Your solution to this could then be solved by having a parent module class, where the login method would reside, and be executable by all the modules.</p> <pre><code>// Your parent class abstract class ParentModule { protected function login() { // Login stuff } } // One of your modules final class ArticleModule extends ParentModule { public function submit_article() { // An example function } } // Another one of your modules that the user could still login from final class AnotherModule extends ParentModule { public function another_command() { // Magic } } </code></pre> <p>Your controller could then look something like the below.</p> <pre><code>$module = new ArticleModule(); $module-&gt;login(); $module-&gt;submit_article(); </code></pre> <p>Lastly, when you get into looking at interfaces - took me forever to understand those - you will again see the benefit of abstract classes. And indeed, if you fully grasp the concept of abstract classes, you will more easily understand interfaces.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload