What if I don't use interfaces in PHP OOP? They are just declaration of function, no implementation at all! Say I don't use interface, then what would happen?
I am somehow unable to get the use of it in PHP.
What if I don't use interfaces in PHP OOP? They are just declaration of function, no implementation at all! Say I don't use interface, then what would happen?
I am somehow unable to get the use of it in PHP.
Suppose there are many kind of Keys, say AES, DES, RSA, EC etc. They have so many different properties with some common properties too!
So you declare classes named AES, DES etc. As they have common properties, (say getKeyValue()
, setKeyValue()
) so your every Key class has these two methods in common.
Now you are going to implement something (say a function which prepare a Key and return it) where you don't know which Key will come to you (or which key you are going to return).
So how you going to handle this thing? Declare all these Key objects to receive the unknown Key? Like the following?
AES aes = ...
DES des = ...
.
.
.
EC ec = ...
What if you just do the following?
Key key = ... // this key object can hold all the keys
So easy, aha? That Key
is an interface where every Key (AES, DES bla bla) implements it!