chacha102 Posted July 29, 2008 Share Posted July 29, 2008 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 More sharing options...
obsidian Posted July 29, 2008 Share Posted July 29, 2008 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 More sharing options...
genericnumber1 Posted July 30, 2008 Share Posted July 30, 2008 As has been stated, I use them most when implementing an API. A lesser used reason I see for interfaces is they let you have multiple lines of inheritance... though I can't say I've ever used them for that reason. Link to comment https://forums.phpfreaks.com/topic/117249-interfaces/#findComment-603772 Share on other sites More sharing options...
DarkWater Posted July 30, 2008 Share Posted July 30, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.