How to register activation and deactivation hook in plugin using OOP pattern

It can be demonstrated like this way:

Step-1: Create a folder named includes (or any name you like) inside the plugin root folder. Create two new files named class-responsive-slider-activator.php and class-responsive-slider-deactivator.php
Now, in class-responsive-slider-activator.php create a class –

class Responsive_Slider_Activator {

    public static function activate() {
         //do your codes to execute upon activation

    }
}

and in class-responsive-slider-deactivator.php create another class-

class Responsive_Slider_Deactivator {

    public static function deactivate() {
         //do your codes to execute upon deactivation

    }
}

Step-2: In main plugin file create functions and register the two hooks –

// this code runs during plugin activation
function activate_responsive_slider() {   

   require_once plugin_dir_path( __FILE__ ) . 'includes/class-responsive-slider-activator.php';

   Responsive_Slider_Activator::activate();
}

register_activation_hook( __FILE__, 'activate_responsive_slider' );


// this code runs during plugin deactivation
function deactivate_responsive_slider() {

   require_once plugin_dir_path( __FILE__ ) . 'includes/class-responsive-slider-deactivator.php';

   Responsive_Slider_Deactivator::activate();
}

register_deactivation_hook( __FILE__, 'deactivate_responsive_slider' );

That’s it.

N.B. – As per your interest, I would like to denote that there are some essential tasks which can be accomplished through activation and deactivation hooks like:

  1. Validating other dependent plugin on activation.
  2. Creating custom database tables on activation to store data and removing tables on deactivation.
  3. Creating custom options for plugins in activation and reset in deactivation.
  4. Any other necessary task need to execute in activation. etc