For those beginners
In fact, their role is very simple, when a lot of people to develop a project, may go to call someone else to write some of the classes, then you will ask, how do I know how his implementation of a function is named, this time the PHP interface class interface play a role, when we define an interface class, The way inside it is that the following subclass must be implemented, such as:
- Interface Shop
- {
- Public function Buy ($gid);
- Public function sell ($GID);
- Public Function view ($GID);
- }
I declare a shop interface class, defines three methods: Buy, Sell (Sell), see (view), then inherit all subclasses of this class must implement these 3 methods less than one, if the subclass does not implement these words, it will not run. In fact, the interface class is plainly, is a class template, a class of provisions, if you belong to this category, you have to follow my rules, less one can not, but specific how you do, I don't care, it is your business, such as:
- Class Baseshop implements Shop
- {
- Public function Buy ($gid)
- {
- Echo (' You have purchased the ID: '. $gid. ' goods ');
- }
- Public function Sell ($gid)
- {
- Echo (' You have sold the ID: '. $gid. ' goods ');
- }
- Public Function view ($gid)
- {
- Echo (' You have viewed the item ID: '. $gid. ');
- }
- }
You think, in a multi-person cooperation of large projects, with the interface class is how convenient, so you do not have to ask others, your method name of the function is what, of course, if you like this I have no way.
Conclusion: PHP Interface class interface is the leader of a class, indicating the direction, the subclass must complete its specified method.
http://www.bkjia.com/PHPjc/446183.html www.bkjia.com true http://www.bkjia.com/PHPjc/446183.html techarticle for those beginners actually their role is very simple, when there are a lot of people to develop a project, may be to call someone else to write some of the classes, then you will ask, how do I know his ...