Skip to main content
added 284 characters in body
Source Link
Austin Salonen
  • 50.4k
  • 16
  • 112
  • 140

A factory is the way to go.

As for the big switch statement, your other options include:

  • Configuration/lookup file
  • A database
  • Reflection

I think the reflection route is the easiest to maintain but the complexity arises when you don't already have the type (assuming your "type" is a Type).

Since you already have the type, the rest is real easy:

public static Task GetByType(Type taskType) { return Activator.CreateInstance(taskType) as Task; } 

A factory is the way to go.

As for the big switch statement, your other options include:

  • Configuration/lookup file
  • A database
  • Reflection

I think the reflection route is the easiest to maintain.

A factory is the way to go.

As for the big switch statement, your other options include:

  • Configuration/lookup file
  • A database
  • Reflection

I think the reflection route is the easiest to maintain but the complexity arises when you don't already have the type (assuming your "type" is a Type).

Since you already have the type, the rest is real easy:

public static Task GetByType(Type taskType) { return Activator.CreateInstance(taskType) as Task; } 
Source Link
Austin Salonen
  • 50.4k
  • 16
  • 112
  • 140

A factory is the way to go.

As for the big switch statement, your other options include:

  • Configuration/lookup file
  • A database
  • Reflection

I think the reflection route is the easiest to maintain.