Click here to Skip to main content
14,836,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP object interface. I have understood the all methods declared in an interface must be public. but for example if i have 10 public methods in my base class which implements interface did i need to add all 10 into the interface delcaration.

What I have tried:

If the answer is "NO" then what type of methods should i need to declare into interface.
Posted
Updated 13-Jan-17 0:45am
v2

1 solution

You are missing the point of using an interface. A class can have its own methods without implementing any interfaces. Apart from its own methods, if it also implements other interfaces, then it has to include and provide implementation details for all the methods specified in those interfaces. In this way, an interface provides a set of common methods that classes of a similar type are contracted to implement them. As an analogy, similar classes of building such as residence, office, classroom must have their own ways to turn on and off the light. To make sure that the builders of such buildings not to forget to implement these methods, they have to sign a contract (interface) which states that they must implement two methods called say turnOn() and turnOff() to turn on and off the light, however leaving out the details of how to do it.
More example PHP: Object Interfaces - Manual[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900