J'ai besoin d'intimité. Non pas parce que mes actions sont douteuses, mais parce que votre jugement et vos intentions le sont.
5200 links
"It seems like many contributors are missing the point of using an INTERFACE. An INTERFACE is not specifically provided for abstraction. That's what a CLASS is used for. Most examples in this article of interfaces could be achieved just as easily using just classes alone.
An INTERFACE is provided so you can describe a set of functions and then hide the final implementation of those functions in an implementing class. This allows you to change the IMPLEMENTATION of those functions without changing how you use it.
For example: I have a database. I want to write a class that accesses the data in my database. I define an interface like this:
interface Database {
function listOrders();
function addOrder();
function removeOrder();
...
}
Then let's say we start out using a MySQL database. So we write a class to access the MySQL database:
class MySqlDatabase implements Database {
function listOrders() {...
}
we write these methods as needed to get to the MySQL database tables. Then you can write your controller to use the interface as such:
$database = new MySqlDatabase();
foreach ($database->listOrders() as $order) {
Then let's say we decide to migrate to an Oracle database. We could write another class to get to the Oracle database as such:
class OracleDatabase implements Database {
public function listOrders() {...
}
Then - to switch our application to use the Oracle database instead of the MySQL database we only have to change ONE LINE of code:
$database = new OracleDatabase();
all other lines of code, such as:
foreach ($database->listOrders() as $order) {
will remain unchanged. The point is - the INTERFACE describes the methods that we need to access our database. It does NOT describe in any way HOW we achieve that. That's what the IMPLEMENTing class does. We can IMPLEMENT this interface as many times as we need in as many different ways as we need. We can then switch between implementations of the interface without impact to our code because the interface defines how we will use it regardless of how it actually works."
ET :
"When should you use interfaces? What are they good for?
Here are two examples.
This allows you to write reusable calling code that can work
for any number of different objects -- you don't need to know
what kind of object it is, as long as it obeys the common
interface.
When I came back to make the changes, I was able to create
some new implementations of these interfaces that added the
extra features I needed. Some of my classes still used
the "basic" implementations, but others needed the
specialized ones. I was able to add the new features to the
objects themselves without rewriting the calling code in most
cases. It was easy to evolve my code in this way because
the changes were mostly isolated -- they didn't spread all
over the place like you might expect."
Enfin, je comprends à quoi sert une interface (Merci à dlovell2001 at yahoo dot com et erik dot zoltan at msn dot com) ! Je n'avais jamais lu les commentaires associés à cette page. J'aurais dû le faire plus tôt.
Moralité : TOUJOURS LIRE LES COMMENTAIRES DES PAGES DE LA DOCUMENTATION PHP !
Je ne vois pas ce qui gène... :)
Merci pour l'astuce. À tester.
Arf :(
Et en plus, il a le charisme d'une huître...
Pas mal :)
Je pense que je vais m'en servir pour le boulot afin de débaucher enfin à l'heure...
Ça fait du bien de temps en temps de remettre les pendules à l'heure.
Au boulot, 17 épinglés, 11 non épinglés mini.
À la maison, minimum 5 mais aucun d'épinglés.
Icones façon iOS.
Articles sur svg à lire. Beaucoup de choses intéressantes et bien expliquées.
Pas mal et très bien expliqué. Et en plus, il y a les plans pour en faire de même à la maison...
Plutôt qu'un autocollant, il faudrait en faire une vraie coque (pour android aussi...)
"C’est le problème habituel du contrôle. Si le logiciel sur votre ordinateur n’est pas un logiciel libre, ce n’est pas réellement votre ordinateur, mais juste un que le fournisseur de logiciel propriétaire vous autorise à utiliser d’une certaine façon, définie par lui."
Tout le problème du logiciel propriétaire est résumé dans cette phrase...
J'adore !!! Et en plus, elle est trop belle (in love) <3
Que de vérités, malheureusement...
D'autres choix politiques sont possibles, autres que ceux que les médias et nos "chers" élus nous assènent.
Oui bien sûr, c'est tiré du pavé dans la mare (http://www.scoplepave.org/travailler-moins-pour-gagner-plus)
Une vision différente sur ce qu'on croit savoir sur le salaire.
A lire et méditer et à faire circuler. "Comme hier, la corde est tendue... très..."