from abc import ABC, abstractmethod


def factory(in_queue=None) -> Primes:
    return PrimesToReturn() if in_queue is None else PrimesToQueue(in_queue)


class Primes(ABC):

    @abstractmethod
    def append(self, prime: int) -> None: pass

    @abstractmethod
    def all(self) -> list[int]: pass


class PrimesToReturn(Primes):
    """
    uses a local array
    """

    def __init__(self) -> None:
        self._primes = []

    def append(self, prime: int) -> None: self._primes.append(prime)

    def all(self) -> list[int]: return self._primes


class PrimesToQueue(Primes):
    """
    uses a queue
    """

    def __init__(self, in_queue) -> None:
        self._queue = in_queue
        self._queue_count = 0

    def append(self, prime: int) -> None:
        self._queue.put(prime)
        self._queue_count += 1

    def all(self) -> list[int]:
        self._queue.put(None)
        return []
