Abstract Factory Pattern in Python I have been reading today about the Abstract Factory Pattern, and tried to make the following implementation.
I have seen a lot of implementations in the internet, where they use switch statements, but I must say that I didn't like that much, since the more factories you make, it seems to me that it makes very difficult to add new products, if needed.
Anyways, I was hoping you to take a look at it and let me know your opinions. Thanks in advance for taking your time to review it.
Factories
from abc import ABC, abstractmethod


class PlayerFactory(ABC):
    &quot;&quot;&quot;
    This class is meant to be an interface
    &quot;&quot;&quot;
    @abstractmethod
    def create_goalkeeper(self):
        pass

    @abstractmethod
    def create_defender(self):
        pass


class FootballPlayerFactory(PlayerFactory):
    def create_goalkeeper(self):
        return FootballGoalkeeper()

    def create_defender(self):
        return FootballDefender()


class HockeyPlayerFactory(PlayerFactory):
    def create_goalkeeper(self):
        return HockeyGoalkeeper()

    def create_defender(self):
        return HockeyDefender()


Football players
class FootballPlayer:
    def __init__(self, uses_hands):
        self.uses_hands = uses_hands

    def play(self):
        print(&quot;I'm playing football!&quot;)


class FootballGoalkeeper(FootballPlayer):
    def __init__(self):
        super(FootballGoalkeeper, self).__init__(uses_hands=True)


class FootballDefender(FootballPlayer):
    def __init__(self):
        super(FootballDefender, self).__init__(uses_hands=False)

Hockey players (my creativity stopped here, so I didn't include any difference between goalkeepers and defenders)
class HockeyPlayer:
    def play(self):
        print(&quot;I'm playing hockey!&quot;)


class HockeyGoalkeeper(HockeyPlayer):
    pass


class HockeyDefender(HockeyPlayer):
    pass
As your code presently stands, you don't need the derived Factory classes.  They don't do anything different from each other, so they can all be handled by a concrete base class.
class PlayerFactory:

    def __init__(self, goal_keeper_class, defender_class):
        self._goal_keeper_class = goal_keeper_class
        self._defender_class = defender_class

    def create_goalkeeper(self):
        return self._goal_keeper_class()

    def create_defender(self):
        return self._defender_class()

player_factory = {
    &quot;Football&quot;: PlayerFactory(FootballGoalkeeper, FootballDefender),
    &quot;Hockey&quot;: PlayerFactory(HockeyGoalkeeper, HockeyDefender),
}

Example Usage:
&gt;&gt;&gt; player = player_factory[&quot;Hockey&quot;].create_defender()
&gt;&gt;&gt; type(player)
&lt;class '__main__.HockeyDefender'&gt;
&gt;&gt;&gt; player.play()
I'm playing hockey!
&gt;&gt;&gt;

If there is some aspect of the factories which actually do something different, and thus necessitate separated derived classes, you'll need to include that in your question.