factory pattern and generics example