Re: What is the practical use of "abstract" and "interface"?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 16, 2008 at 12:01 PM, Robert Cummings <robert@xxxxxxxxxxxxx>
wrote:

>
> On Wed, 2008-04-16 at 17:22 +0100, Robin Vickery wrote:
> > On 16/04/2008, Jay Blanchard <jblanchard@xxxxxxxxxx> wrote:
> > > [snip]
> > >  > What about encapsulation?
> > >
> > >  Interfaces have nothing to do with encapsulation for the smple reason
> > >  that I
> > >  can have encapsulation without using interfaces.
> >
> > Unique use of logic there.
> >
> > By similar reasoning; swimming trunks have nothing to do with swimming
> > for the simple reason that I can swim without trunks.
> >
> > > You are still missing the fundamental point. There is absolutely
> > > nothing I can do WITH interfaces that I cannot do WITHOUT them,
> > > therefore they are redundant.
> >
> > How about compile-time checking that the interface has been correctly
> > implemented?
>
> Exactly, I was about to write the same line to Tony. Yes, you can do
> everything without interfaces (and I do), but some people like the
> safety net of compile time checks for full implementation of the
> interfaces requirements... the problem is when you're testing the
> buildup of code for an interface, you often make function stubs until
> you get to them... and you might forget one ;)


yes; i like them a lot. they make concepts explicit and code easier to
understand.  its very clear that when implementing an interface, in the
technical terms of the language (php), that you have to fill in all the
blanks.  on the contrary, w/o the keyword hopefully youll be able to test in
development and catch those missing blanks before the code ships off to
production :)

but  heres the way i look at it, if youre in a class thats been hanging
around for a while, you see a bunch of methods in there that are
'implicitly' implementing an interface, it could take you some time to
determine why theyre even there in the first place.  in which case, youll
have to rely on good documentation of the code.  interfaces take this to a
higher level, and make it very clear why a certain set of functions are in
the code.

if you ask me; interfaces are awesome; theyre lightweight versions of
abstract classes or in c++ terms they are purely virtual classes.  you dont
run the risk of getting a bunch of potentially harmful behavior from a
abstract base class; and you dont bloat up a class hierarchy either.  in
fact, thats where the interface keyword came from, if im not mistaken.  back
in the day, the c++ guys were writing virtual classes where every method was
virtual.  java took it one step further; they determined, well theres this
trend here; why dont we bring it to the fore and give it a particular term.

php has simply followed suit w/ this most excellent paradigm.

btw. everything i said in the conversation 6 months back is still valid and
i stand behind every bit of it.

to OP; grab a design patterns book, like heads first, gang of four, or
martin fowler - patterns of enterprise application architecture for great
practical examples of interface keyword application.  you might also look
through the archives about an example i posted for the multiple inheritance
workaround using interfaces and composition.  this is the java way, and now
ultimately the php way as well :D

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux