Search

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.

  • When is the benefit greater to incorporate methods into the driver?
  • When is it more beneficial to break them out into their own class?
  • Does anyone have any concrete guidelines regarding this that they use when developing extensions?

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!

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.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details