Tags

, ,


Get my all books here….

https://leanpub.com/u/sanjibsinha

Laravel Authentication

Abstraction in OOP involves extraction of relevant details. Consider the role of a car salesman. There are many types of consumers. Everyone wants to buy a car, no doubt, but each one has differences in their criteria. Each of them is interested in one or two certain features. This attribute varies accordingly. Shape, color, engine power, power steering, price … the list is endless. The salesman knows all the details of the car but does he repeat the list one by one until someone finds his or her choice?
No.
He presents only the relevant information to the potential customer. As a result the salesman practices “Abstraction” and presents only relevant details to customer. Now consider abstraction from the perspective of a programmer who wants a user to add items to list.
Abstraction does not mean that information is unavailable but it assures that the relevant information is provided to the user. PHP 5 had introduced abstract classes and methods much before. And PHP 7 enhances it now making the general purpose language completely object oriented. Classes defined as abstract may not be instantiated and any class that contains at least one abstract method must also be abstract.
Remember that abstract methods can not define the implementation. On the other hand, object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.
Interfaces are defined with the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined.
All methods declared in an interface must be public; this is the nature of an interface. In Laravel, you will find the injection of interfaces to the classes quite frequently. In Laravel Interface is considered as a Contract.
Contract between whom? And why? Because an interface does not contain any code but it only defines a set of methods that an object implements. In SOLID design principle we have talked about maintaining a library of small classes with clearly defined scopes, and it is achievable with the help of Interfaces.