Factory design pattern and interfaces
A CLASS is often described as a blueprint for objects that are created from it. It specifies the behaviour of its instances and the data they contain (as methods and member variables, respectively).
In a similar way, an interface can be described as a set of requirements for classes. It can be regarded as a contract that specifies what methods should be present in the classes derived from it.
Taking manufacturing as an analogy, the interface represents the product specifications, and the class, the manufacturing specifications; the interface states what the product should look like, and the class describes what goes in the product.
Because the interface is such an abstract concept, many beginners in OOP fail to recognise how useful it can be for improving the design and robustness of their applications.
Here, I will try to demonstrate how the power of interfaces can be harnessed to add flexibility to an application.
Powered by WordPress and Eddy Young.