Challenge: you need a flexible (swap in other repository implementations) way to display some kind of resource. Let's say, Posts. What does your folder structure look like?
Requirements:
- Repository implements an interface
- Must show at least one implementation of the interface (Eloquent version is fine)
- The interface is injected into your PostsController.
- Show where you register your IoC bindings
- Show folder structure. Where are interfaces/repositories stored?
@ccovey - Assuming you mean an abstract instead of an interface, I'd say:
Short answer: yes
Longer Answer: Interfaces are a better over-all use
The utility of Interfaces is the contract (the guarantee) that you'll have a method implemented. In your example, an Interface can guarantee that you'll have a find() method, and that method will take a parameter.
Extending classes can break that guarantee. Interfaces are therefore the better way to go.
It's a form of enforcement which leads to clearer code. However inheritance can mostly do that for you.