Zend certified PHP/Magento developer

How do we know which factories class need to use in Magento2?

This is the code I copied from MagePlaza.
class Index extends MagentoFrameworkAppActionAction
{
protected $_pageFactory;

public function __construct(
    MagentoFrameworkAppActionContext $context,
    MagentoFrameworkViewResultPageFactory $pageFactory)
{
    $this->_pageFactory = $pageFactory;
    return parent::__construct($context);
}

public function execute()
{
    return $this->_pageFactory->create();
}

}

How we will decide that here we need to use PageFactory and why we pass MagentoFrameworkAppActionContext in the constructor.

Can anyone help me out this please?