Re: A Good OOP Tutorial/Read?

From: Date: Fri, 17 May 2013 14:44:05 +0000
Subject: Re: A Good OOP Tutorial/Read?
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.general 
Request: Send a blank email to php-general+get-321107@lists.php.net to get a copy of this message
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 <tedd.sperling@gmail.com> wrote:
Stuart: You said:
An interface does what it says on the tin: it describes an interfacethat a class can then tell the world it implements. An abstract class provides functionality as well as an interfacedescription. An abstract class cannot be instantiated, it can only beextended. The logging example given by someone earlier in this thread is the mostcommon example given for interfaces. This is where the interface isdefined as an API for others to implement and/or use which then enablesusers to pick and choose the combination of implementations they wantto use based on their requirements without needing to change any of thecode of either class.
I understand the "stated" differences between abstract and interface. Ican cite what the differences are, but I don't see the practicalapplication 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 youwant 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 atabstract thinking -- I need a concrete simple example. I tried to create a demo where I had a Toaster Class that containedbreadNumber() 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 Ican easily explain why they are important? Thanks, tedd _____________________ tedd.sperling@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#321107) next »