Creating 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

Post Reply
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Creating interfaces

Post by jmut »

I see interfaces is good thing to let know what methods class implements.
And if one wants to use stuff he need to impelement this and that interface to stick together with API or whatever.
So my question is....we now what methods should be implemented (the interface defines this) but we don't know what the result should be.
Is this PHP lacks or is it common problem....maybe I don't get something right.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

I have not the slightest idea what you're talking about. Care to write out a bit more clearly what you mean?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

jmut wrote:Is this PHP lacks or is it common problem....maybe I don't get something right.
Considering PHP is a typeless language, it's rather retarded to have return types. Good documentation of the code should tell someone building their own interface what should be returned. Unit tests would also help as it would give you a black'n'white definitive as to your implementation falling into expected results. There's the potential for not-so-great test suites however, so good, up-to-date documentation is still important.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

There is also the broader question of whether Interfaces are really very useful in PHP. From what I have seen they are only really useful in some special cases where a you need to know about the general type of an object -- for Dependency Injection for example. Otherwise they are just extra parsing to provide error messages that should probably be dealt with in other ways, like unit testing.
(#10850)
Post Reply