Prev | Current Page 680 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

Interfaces represent a common feature
in modern object-oriented languages. An interface represents a set of methods that a class must define when
implementing the interface.
When a class implements an interface, it is required to implement all the methods defined by that
interface. This way, the interface becomes a contract that guarantees the classes that implement it contain
a certain set of methods. For example, in the exercise that follows we??™ll create an interface named
IPipelineSection that contains a single method named Process():
interface IPipelineSection
{
public function Process($processor);
}
We??™ll implement this interface in all the classes that represent pipeline sections (we??™ll write them in the
next chapter), ensuring that each of these classes will include a method named Process(). This way, when
working with order pipeline classes, we??™ll be able to safely call the Process() method on them because we??™ll
be guaranteed this method will be there.
An interface cannot be instantiated like a normal class because it doesn??™t contain any method implementations,
only their signatures. (A method signature is simply a method definition with no code.)
Classes implement interfaces using the implements operator. A class can implement multiple interfaces,
but these interfaces must not contain the same method in order to avoid ambiguity.


Pages:
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
kły tokarskie Perfumy Cesarskie cięcie bizuteria recznie robiona pilarki