Re: [PHP] A Good OOP Tutorial/Read?

[email protected] (Přemysl Fiala)
Newsgroups php.general
Organization Laboratory Imaging
Message-ID <[email protected]>
Interfaces...I will add my 2 cents to what was already said.

You don't need them, but they improve quality of your code. Your  
application is easily maintained, improved, understandable, accessible,    
more cleaner, modules can be added easily...

They implements some behavior (example):

interface toastAble
{
     function toast($bread);
}

interface talkAble
{
    function sayHello();
}

abstract class AToaster implements toastAble
{
    function toast($bread)
   {
      $bread->state = STATE_DELICIOUS;
    }
}

class TalkingToaster extends AToaster implements talkAble
{
     function sayHello()
     {
       echo "Hello, would you like to toast your bread?";
     }
}

$toaster = new  TalkingToaster();
$toaster->sayHello();


Premek.

On Fri, 17 May 2013 16:04:40 +0200, Tedd Sperling  
<[email protected]> wrote:

> Stuart:
>
> You said:
>
>> An interface does what it says on the tin: it describes an interface 
>> that a class can then tell the world it implements.
>>
>> An abstract class provides functionality as well as an interface 
>> description. An abstract class cannot be instantiated, it can only be 
>> extended.
>>
>> The logging example given by someone earlier in this thread is the most 
>> common example given for interfaces. This is where the interface is 
>> defined as an API for others to implement and/or use which then enables 
>> users to pick and choose the combination of implementations they wantto  
>> use based on their requirements without needing to change any of the 
>> code of either class.
>
> I understand the "stated" differences between abstract and interface. I 
> can cite what the differences are, but I don't see the practical 
> application differences. To me there is no difference between anabstract  
> class (without method declarations) and an interface.
>
> However, I view an interface as a statement (a contract) where IF you 
> want someone to use your code you outline the methods you require themto  
> flesh-out in their code -- but I would like to see a simple exampleof  
> that.
>
> I vaguely get the logging example given by Larry, but I'm not good at 
> abstract thinking -- I need a concrete simple example.
>
> I tried to create a demo where I had a Toaster Class that contained 
> breadNumber() and toastSetting() methods and then created an interfaceso  
> my students could use the Toaster, but it didn't really hold up aswell  
> as I wanted.
>
> So, can anyone give me a simple example where an interface is used so I 
> can easily explain why they are important?
>
> Thanks,
>
> tedd
>
>
> _____________________
> [email protected]
> http://sperling.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.