{"id":455,"date":"2010-01-06T20:47:43","date_gmt":"2010-01-06T20:47:43","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=455"},"modified":"2010-01-06T21:34:49","modified_gmt":"2010-01-06T21:34:49","slug":"interfaces-the-abstract-class","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/01\/06\/interfaces-the-abstract-class\/","title":{"rendered":"Interfaces &#8211; the abstract class"},"content":{"rendered":"<p>An interface, as described further on the php.net website <a href=\"http:\/\/uk.php.net\/interface\">here<\/a>, is basically a abstract class that defines a skeleton of what a class will have to at least implement, this allows for classes to implement a set skeleton and you will know what functions that class will have to implement.<\/p>\n<p>The interface is just that, a skeleton of a base class.  e.g. a interface could be a shape, and the classes that implement the interface called shape could be circle, square etc..because they will all have the basic functions for example, shape sides, colour etc.<\/p>\n<p>Here is some php code, I always find looking over code easier to understand the basics of things.<\/p>\n<pre lang=\"php\">\r\n<?php\r\n\r\n\/* this is a adstract class, e.g. any class that implements this class will have to implement all of the \r\n  skeleton functions that this class as defined \r\n  \r\n  the abstract class is defined with the \"interface\" type *\/\r\n  \r\ninterface Skeleton {\r\n    public function printOutAWord($theWord);\r\n    \r\n    public function printOutAArray($theArray);\r\n}\r\n\r\n\/* \r\n  this class, TheWorker, will actually \"implement\" the abstract class Skeleton, via the \r\n  implemets syntax  *\/\r\n  \r\nclass TheWorker implements Skeleton {\r\n    \/\/ these are the functions code that was defined by the abstract class.\r\n    public function printOutAWord($theWord)\r\n    {\r\n\techo \"\\n$theWord\\n\";\r\n    }\r\n    \r\n    public function printOutAArray($theArray)\r\n    {\r\n\techo \"\\n\". print_r($theArray).\"\\n\";\r\n    }\r\n}\r\n\r\n$newWorker = new TheWorker();\r\n\r\n$newWorker->printOutAWord(\"Printing out a word\");\r\n\r\n$newWorker->printOutAArray(array(\"Array\",\"words\",\"are\",\"here\"));\r\n?>\r\n<\/pre>\n<p>And the output would be this<\/p>\n<pre lang=\"bash\">\r\nPrinting out a word\r\nArray\r\n(\r\n    [0] => Array\r\n    [1] => words\r\n    [2] => are\r\n    [3] => here\r\n)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>An interface, as described further on the php.net website here, is basically a abstract class that defines a skeleton of what a class will have to at least implement, this allows for classes to implement a set skeleton and you will know what functions that class will have to implement. The interface is just that, &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/01\/06\/interfaces-the-abstract-class\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Interfaces &#8211; the abstract class<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[50],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-php","tag-interfaces"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=455"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/455\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}