Skip to content

Instantly share code, notes, and snippets.

@juancho088
Last active June 17, 2018 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juancho088/fe005a572dc645e96aa5484e508c90ac to your computer and use it in GitHub Desktop.
Save juancho088/fe005a572dc645e96aa5484e508c90ac to your computer and use it in GitHub Desktop.
package com.myblockbuster.core.factories
import com.myblockbuster.core.User
import com.myblockbuster.core.services.Service
import com.myblockbuster.movies.Movie
import com.myblockbuster.movies.services.MovieService
/**
* Interface Factory
*/
interface Factory
/**
* Creates a Service according to the Entity type to manage
*/
class ServiceFactory<T>: Factory {
fun <T : Any> getService(type: Class<T>): Service<T, User> {
return when (type) {
Movie::class.java -> MovieService() as Service<T, User>
else -> throw IllegalArgumentException()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment