Pour savoir dans votre code voici ce qu'il faut faire :

 

if (Factory::getApplication()->bootComponent($extension)->getMVCFactory() instanceof \Joomla\CMS\MVC\Factory\LegacyFactory){
// mode Legacy MVC Joomla3
....
}else{
// Mode MVC Joomla4 et + natif
...
}