Extension Development: Drivers vs Classes
This is an open discussion with 3 replies, filed under Extensions.
Search
I personally think it would be better not to overfill the extension driver. I think that having a library class with all the grouped methods is better for re-usability so you can reference it from the extension driver, also create a dashboard panel with it, or even create it's own content page.
Anything that's inherently not Symphony based, like calling separate Google Analytics API calls should be a class in it's own right.
Saying that, I'm still trying to get my head around OOP
I like to pull extension methods out, usually into a standalone class with static methods in a lib
folder. This lets me reuse my class at any point without having to reference an instantiated extension object. I like to keep the extension driver as a pure driver, just the pieces that are needed to interface with Symphony itself (the methods that a driver class can implement, such as about
, install
, update
), and anything extension-specific into a class. Basic extensions require a single class, but imagine if your Google Analytics extension required additional classes, perhaps GoogleAnalyticsClient
, GoogleAnalyticsReport
and so on, you'd want those as separate classes outside of the driver.
In the grand scheme of things, it is down to your own coding style :-)
It is settled then! Thanks guys :)
Create an account or sign in to comment.
I feel like this is been discussed before but I could not find any past discussions from searching.
As I continue work on the Google Analytics extension, I can't decide whether to create a separate class or add methods to the extension's driver.
For this particular extension, I don't see a need for an interface or abstract classes. While there may be benefits to utilizing inheritance, I think it would be overkill. So, I'm left with a simple basic class and I can't decide if I should leave it as is or just add the methods to the extension's driver.
My github repository is out-of-date and a mess, so please don't reference it (I was just trying to get something to work with Google's API).
What is your, "best practice" advice?
Cheers!