Click here to Skip to main content
13,191,638 members (66,134 online)
Rate this:
 
Please Sign up or sign in to vote.
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 12-Jan-17 22:01pm
Arun-23709
Updated 13-Jan-17 0:45am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.171017.2 | Last Updated 13 Jan 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100