Interfaces?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Bruno De Barros
Forum Commoner
Posts: 82
Joined: Mon May 12, 2008 8:41 am
Location: Ireland

Re: Interfaces?

Post by Bruno De Barros »

I'd say, for interfaces...

class Bee implements live_being, flying_being {

It's a live_being, and it HAS to breath, feed and reproduce.
It's a flying_being, so it also HAS to fly.

But not all live beings breath the same way, feed the same and reproduce the same way.
And not all flying_beings fly the same way, but they do fly.

So the Bee has to breath, feed and reproduce, as well as fly, but it does it in its own way.

}

It's good if you want multiple of the same thing, like different Template Parsers or different Database Abstractors. All have to do the same things, but they can do it the same way. If I knew of interfaces, a framework I was planning to do a long time ago would benefit a lot from it, as I had to explicitly say you could create your own drivers, but they had to have the same function names as the original ones, to keep compatibility with other apps relying on them.
dml
Forum Contributor
Posts: 133
Joined: Sat Jan 26, 2008 2:20 pm

Re: Interfaces?

Post by dml »

class Bee implements live_being, flying_being
Indeed, though if you're looking for "natural" interfaces, it's better to think in terms of desired interactions rather than classifications: for example a flower has an "interface" to encourage and allow bees to land on it and pollinate it (or whatever bees do that's of benefit to a flower).
...I had to explicitly say you could create your own drivers, but they had to have the same function names as the original ones, to keep compatibility with other apps relying on them.
That's what's known as duck typing

There are interfaces all over the place: for example cameras with pluggable lenses; containerisation in transport, where shippers are required to "wrap" their cargo in a standard interface for which the infrastructure can be optimised; rail gauges, which allowed for division of labour between engineers who put down rails and engineers who built trains to run on them.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Interfaces?

Post by Jenk »

Let's not forget more every day interfaces, too.. the keyboard you are typing on.. the monitor you are looking at. The keypad on your phone, the key you use to let you through the door.. etc.

These are all common interfaces, but there are many different objects that use these interfaces.
Post Reply