Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Develop] Improve extensibility #219

Closed
wants to merge 3 commits into from

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Sep 5, 2014

The changes in this PR allow for the class to be extended from a child class for a specific implementation.

The way the class was set up, extending from a child class would mean overloading a truck load of methods to get round the hard coded class name and some more convoluted coding to overrule the instance and the auto-instantiation of the class.
These changes take the pain out of extending the class and make it so this library can have a clean upgrade path even when you extend the class.

Details:

  • Wrap instantiation in a hooked function (so it can be unhooked)
  • Use the global to get to the instance.
    This allows for an extended child class to set the global and for everything to still work provided the child class provides their own static get_instance() method which sets their own static $instance property.
  • Force instantiation via get_instance() by making the constructor protected

This allows for an extended child class to set the global and for everything to still work provided the child class provides their own static `get_instance()` method which sets their own static `$instance` property.
@jrfnl jrfnl force-pushed the Improve-extensibility branch from 196aa59 to 36c4fcd Compare September 7, 2014 11:05
@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 7, 2014

Originally - this PR also contained the changes from PR #221 , but it made more sense to split the PR as - while related -, they really are two different things.

@jrfnl jrfnl changed the title Improve extensibility [Develop] Improve extensibility Jan 13, 2015
jrfnl added a commit to jrfnl/TGM-Plugin-Activation that referenced this pull request Jan 14, 2015
@GaryJones
Copy link
Member

I'm +1 for this.

if ( ! isset( self::$instance ) && ! ( self::$instance instanceof TGM_Plugin_Activation ) ) {
self::$instance = new TGM_Plugin_Activation();
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
self::$instance = new self();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having an untestable singleton class, how about we put a static into load_tgm_plugin_activation() instead?

GaryJones added a commit that referenced this pull request Apr 22, 2015
…implementation

The way the class was set up, extending from a child class would mean overloading a truck load of methods to get round the hard coded class name and some more convoluted coding to overrule the instance and the auto-instantiation of the class.
These changes take the pain out of extending the class and make it so this library can have a clean upgrade path even when you extend the class.

Details:

* Wrap instantiation in a hooked function (so it can be unhooked)
* Use the global to get to the instance. This allows for an extended child class to set the global and for everything to still work provided the child class provides their own static `get_instance()` method which sets their own static `$instance` property.
* Force instantiation via `get_instance()` by making the constructor protected.

props jrfnl, see #219
@GaryJones
Copy link
Member

Applied manually in 7ce1ea0. Thanks @jrfnl.

@GaryJones GaryJones closed this Apr 22, 2015
@jrfnl jrfnl deleted the Improve-extensibility branch April 22, 2015 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants