In template design pattern, should the extended class implements interface or the parent class?
Hi,
I just watched the video "Template design pattern" of "Design Patterns in PHP" series. But I'm confused by the source code in Github repository "laracasts/GitHub-Authentication-With-Laravel" -
I see abstract class Provider doesn't explicitly implements "Provider" interface, however the extended class "Github" implements "ProviderInterface". I don't understand why abstract class Provider doesn't... did I miss something here?
You haven't missed anything. I've watched that long time ago so I do not remember any specifics, but you can see in a bunch of videos those small mistakes or missing pieces which are completely normal when trying to fit everything into a concise lesson.
You can go either way. Depends what will make sense for the feature you are building. Most developers agree that the composition is better than inheritance. You can force composition through inheritance, but you can also force it without inheritance. There is not exact science here where you can say one is better. I usually do not force composition through inheritance. I rarely use abstract classes and almost always default to composition. But if you want to force something on all models then maybe inheritance and abstract class would be better way.