SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Interfaces in frameworks

    Hi,

    i was just studying the code of the binarycloud and the mojavi framework to get better knowledge on how patterns are used in PHP.
    Now i noticed something verry unusual, i cant find one single interface in the application/framework code , this has to have a particulair reason no ?

    Anyone?
    cheers
    Galo
    Business as usual is off the menu folks, ...

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you looking at PHP5 versions of each?
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    Are you looking at PHP5 versions of each?
    Sorry, yes i am...
    Business as usual is off the menu folks, ...

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Location
    United Kingdom
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I find that, especially when designing a framework, there are many cases where you'd use an Abstract Class instead so that you can encapsulate some standard behaviour. Of course, you'd lose the ability to implement multiple interfaces, but sometimes, that simply doesn't crop up.

    Note: this is especially the case with PHP, since it's dynamic typing means that authors don't have to create a "common type" for classes using an interface unless they use type-hinting for everything, last time I looked at the mojavi source, type-hinting was fairly absent.

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Part of the explanation could also be that they both started out as php4 implementations, and thus the design would already have a lot abstract classes to fill the place of interfaces.

  6. #6
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    Part of the explanation could also be that they both started out as php4 implementations, and thus the design would already have a lot abstract classes to fill the place of interfaces.

    yeah but if you are going to realse a new version based on PHP5 you would expect them to refactor saome abstractions to interfaces no ?
    Business as usual is off the menu folks, ...

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe, though I suspect that they've just gone an ported version 4 to version 5 as a means to get their feet wet with PHP5?

    They are after all catering for consumer demand, and this would be the best short term measure to take in my view. Medium term they may take the time to do a complete re-write of the framework to suit PHP5 in a better fashion

  8. #8
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Maybe, though I suspect that they've just gone an ported version 4 to version 5 as a means to get their feet wet with PHP5?

    They are after all catering for consumer demand, and this would be the best short term measure to take in my view. Medium term they may take the time to do a complete re-write of the framework to suit PHP5 in a better fashion
    Alright so this is nothing specific to due with the fact that it both are Frameworks. I thought it had something to do with the fact that it's a framework application and maybe there was a particulair reason to choose abstraction over interfacing. thanks!
    Business as usual is off the menu folks, ...

  9. #9
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All the responses above make the assumption that because interfaces are part of PHP5 they are a useful thing. I think this has yet to be broadly proven. And the lack of them in real implementations may indicate that they are not very useful in practice.
    Christopher

  10. #10
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Galo
    I thought it had something to do with the fact that it's a framework application and maybe there was a particulair reason to choose abstraction over interfacing.
    On the contrary I'd say - frameworks are highly abstract applications, and are meant to provide co-operation (among other things). Interfaces should be a good tool for that task.

    Christopher might very well have a valid point though. It has been argumented that php due to it's very loose typing, might not really benifit much from interfaces.

  11. #11
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    On the contrary I'd say - frameworks are highly abstract applications, and are meant to provide co-operation (among other things). Interfaces should be a good tool for that task.

    Christopher might very well have a valid point though. It has been argumented that php due to it's very loose typing, might not really benifit much from interfaces.
    I know PHP is looe typed but that has nothing to due with using abstraction over interfacing, i found that by using interfaces you can set up your app more detailed.

    I once even designed a complete application just by first mocking up all the interfaces it would be using, specifying the methods of eacht interface and then writing the classes, although im not sure this is a common way of developement, i had a lot of phun and it seemed that by just looking at the interfaces i had a complete overview on the whole app.

    If you push yourself to work like this, then you can easely see what part is going to handle what part, say for example i have a collection interface named ICollect, and it serves me with methods like, "add", "fetch", "size", "keys", "remove", this now can be REUSED to not only provide a machanism for let's say a storage collection stack but also could it be used to manage a collection of files (directory) on a harddrive

    Now try and do this with abstract classes, you need an collectionIterator, IteratorAggregate and a Observer class, and extend them.....no wait,,...erm.... see what i mean. With interfaces this is just more straight forward.

    -Galo
    Business as usual is off the menu folks, ...

  12. #12
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On the contrary I'd say - frameworks are highly abstract applications, and are meant to provide co-operation (among other things). Interfaces should be a good tool for that task.
    Agree with you 100 percent. The larger the framework, the more important it is that you have separation. By the larger the framework, I'm not talking the number of classes or files, I'm talking about the framework distribution.

    I'm talking about what and who uses the framework, and the purpose of the framework in a environment where the framework is shared between resources, ie Users for one?

    And the lack of them in real implementations may indicate that they are not very useful in practice.
    In so far, this could be true... A lot of PHP developers are not by their nature, educated, myself included (I don't have a CS degree), and in saying that they thus far have only experience with PHP4.x which we all know has a lesser object model.

    Now that we have PHP5 we have a better, bolder and bigger object model which supports Interfaces and proper class abstraction. This takes time for a lot of people to sit up and notice this. A lot of people may care less because they don't fully understand the benifits of what Interfaces have to offer?

    I am only aware of Interfaces, etc and the benifits due to some experience with Java. And now let's be honest here, you couldn't for the life of you, develop a Java application without using Interfaces, and the other features that Java has. You couldn't, simple as that.

    PHP is heading towards that same direction, and that is why I can't understand this statement,

    It has been argumented that php due to it's very loose typing, might not really benifit much from interfaces.
    An object model is an object model, regardless of the language, either it be compiled or otherwise. I just don't get where your coming from

  13. #13
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Galo
    I once even designed a complete application just by first mocking up all the interfaces it would be using, specifying the methods of eacht interface and then writing the classes, although im not sure this is a common way of developement, i had a lot of phun and it seemed that by just looking at the interfaces i had a complete overview on the whole app.
    Well, while this is a very good and common approach - to design the skeleton of your classes and then flesh out the implementation - if this is all you are using interfaces for, then in reality you don't need interfaces at all. And as far as the ability to see a method list of each of your interfaces describing the purpose of it, you have that same ability with modern, introspecting IDE's such as ZDE, without the need to use interfaces.

    I am in the same camp as arborint; I have yet to be convinced that interfaces are all that useful in PHP, or at least as they relate to my particular development process, and that of the majority of PHP developers. After all, isn't interfaces a way to allow the programmer to extend the built in types of the language with custom ones? And if so, does this really make sense in a loosely typed language?
    Garcia

  14. #14
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ghurtado
    Well, while this is a very good and common approach - to design the skeleton of your classes and then flesh out the implementation - if this is all you are using interfaces for, then in reality you don't need interfaces at all. And as far as the ability to see a method list of each of your interfaces describing the purpose of it, you have that same ability with modern, introspecting IDE's such as ZDE, without the need to use interfaces.

    I am in the same camp as arborint; I have yet to be convinced that interfaces are all that useful in PHP, or at least as they relate to my particular development process, and that of the majority of PHP developers. After all, isn't interfaces a way to allow the programmer to extend the built in types of the language with custom ones? And if so, does this really make sense in a loosely typed language?
    I see where you're comming from, let me give you one simple example :

    1. oDoor
    2. oJar
    3. iOpenable

    Code:
    interface iOpenable{
          abstract function open();
          abstract function close();
    }
    
    <?php
    
    require_once('inc.openable.php');
    
    class Door implements iOpenable{
          
          private $_locked = false;
          
          public function open(){
                if($this->_locked){
                      print("Door is locked!");
                }else{
                      print("Opened door!")
                }
          }
    
          public function close(){
                print("BAF!");
          }
    
          //etc
    }
    
    class Jar implements iOpenable{
    
          private $_contents;
    
          public function __construct($contents){
                $this->_contents = $contents
          }
    
          public function open(){
                print("Opened Jar!");
          }
    
          public function close(){
                print("Closed Jar!");
          }
    }
    
    function openSomething(iOpenable $oOpenable){
          $oOpenable->open();
    }
    
    $oDoor = new Door();
    $oJar   = new Jar("milk");
    
    openSomething($oDoor);
    openSomething($oJar);
    
    ?>
    Hope this clears up some doubts
    -Galo
    Business as usual is off the menu folks, ...

  15. #15
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Galo
    Hope this clears up some doubts
    It does, and it just occurred to me that in the haste of my post I forgot about the fact that objects can implement multiple interfaces, which might be the most solid argument towards use of interfaces on PHP.

    In playing devil's advocate, I might just be looking for good examples that show me why interfaces are a useful idiom in PHP. Perhaps I am just begging to be converted?
    Garcia

  16. #16
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I forgot about the fact that objects can implement multiple interfaces, which might be the most solid argument towards use of interfaces on PHP.
    In Java circles, these are known as 'Fat Interfaces' if anyone is interested in learning more? You now have a term to Google with


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •