Jump to content

Interfaces


chacha102

Recommended Posts

This may be a really stupid question that I just haven't figured out yet/ (I've only done php for 1-2 years). What are the benefits of using an interface on a class? I realize that you can make sure that certain methods are used, but is that all? Is there some great functionality that I haven't learned yet?

Link to comment
https://forums.phpfreaks.com/topic/117249-interfaces/
Share on other sites

This may be a really stupid question that I just haven't figured out yet/ (I've only done php for 1-2 years). What are the benefits of using an interface on a class? I realize that you can make sure that certain methods are used, but is that all? Is there some great functionality that I haven't learned yet?

 

In my personal experience, interfaces have been most practical when I have worked with a team of developers, because it allows me to define a set of rules to be followed and I can dole out the individual classes to be developed by team members knowing they will fit my API because they implement my interface. I very seldom use them personally unless I am trying to follow a specific API for multiple different classes or modules within a larger framework. I'm sure there are other pros to using them, but I will let those more well versed than I point them out ;)

Link to comment
https://forums.phpfreaks.com/topic/117249-interfaces/#findComment-603138
Share on other sites

I use them, like most people do, for APIs and making sure everything plays nicely together by following a strict format (that way the actual type of object isn't that important.  They'll all work the same if they have the same public functions as defined by an interface).  I also use them for grouping objects.  I know in Java that it's called the Marker pattern.  I'm pretty sure that it's called the same thing.  It's only useful in PHP5 where we have type hinting though.

Link to comment
https://forums.phpfreaks.com/topic/117249-interfaces/#findComment-603773
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.