note 82346 added to language.oop5.interfaces

From: Date: Mon, 07 Apr 2008 12:41:44 +0000
Subject: note 82346 added to language.oop5.interfaces
Groups: php.notes 
Request: Send a blank email to php-notes+get-137997@lists.php.net to get a copy of this message
php at wallbash dot com's comment of "It's important to note this because it is very unexpected behavior and renders many common Interface completly useless" doesn't make sense. the idea of the interface is to force objects that aren't related to be reused in a common way. without them, to force that requirement, all objects that need those methods implemented would have to be descended from a base class that's known to have those methods. that's clearly not a smart idea if these objects aren't actually related. one example (that i'm currently working on) is a background service that pulls information down from different content providers. i have a transport and i have an import. for both, what actually happens in the background is different from provider to provider, but since i'm implementing a transport & import interface, i only need to write code once, because i know exactly the what methods will be implemented to get the job done. then, i just have a config file that loads the class dynamically. i don't need something like if ( $provider == "some company" ) { // use this set of code } elseif ( $provider == "another company" ) { // use this other set of code } instead, i can do: foreach ( $providers as $provider => $info ) { $_transport = $info['transportObject']; $transport = new $_transport(); $_import = $info['importObject']; $import = new $_import(); $transport->setImporter( $import ); $transport->retrieve(); } it is expected behavior that when a class implements two interfaces that share one or more method names, an error is thrown, because interfaces don't relate to each other. if you want that sort of inferred behavior (i.e. A and B are different except for these shared methods), stick to [abstract] classes. it sucks that interface methods might collide for some common types of tasks (get(), set(), etc.), so knowing that, design your interfaces with more unique method names. ---- Server IP: 64.71.164.2 Probable Submitter: 141.156.176.88 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php Edit -- https://master.php.net/note/edit/82346 Del: integrated -- https://master.php.net/note/delete/82346/integrated Del: useless -- https://master.php.net/note/delete/82346/useless Del: bad code -- https://master.php.net/note/delete/82346/bad+code Del: spam -- https://master.php.net/note/delete/82346/spam Del: non-english -- https://master.php.net/note/delete/82346/non-english Del: in docs -- https://master.php.net/note/delete/82346/in+docs Del: other reasons-- https://master.php.net/note/delete/82346 Reject -- https://master.php.net/note/reject/82346 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137997) next »