I'm working with an application that needs to receive several videos, and display them on a particular page, currently these videos can only be from YouTube, due to an implementation that does not allow other providers, because the code to get the video data, as a preview image, was placed directly in the View Helper responsible for displaying the video.
I want to change this structure to make it easy to add new providers, such as Vimeo, and I think the Strategy pattern would be the ideal, I would have in my View Helper the method setVideoUrl( string $url )
, this method would call the method getProviderStrategy( string $url )
from the class VideoProviderFactory
, this factory class would then return, if available, the strategy class, that implements the interface VideoProvider
, for the provider of the video url.
What do you think? This is correct? I Need to change something?
Detail: I initially thought about putting a switch to choose the strategy directly into the View Helper, but after reading this question: I Strategy Pattern with no 'switch' statements? I saw that I was wrong, then the class VideoProviderFactory
showed up.