Skip to content

Instantly share code, notes, and snippets.

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 jarhart/3057950 to your computer and use it in GitHub Desktop.
Save jarhart/3057950 to your computer and use it in GitHub Desktop.
any way to make this cleaner?
abstract class SuperClass {
var initialized = false
def initialize {
initialized = true
}
}
abstract trait MetaClass[A <: SuperClass] { self: A =>
def apply(): A = {
val obj = newInstance
newInstance.initialize
obj
}
protected def newInstance: A
}
object Subclass1 extends SuperClass with MetaClass[Subclass1] {
def newInstance = new Subclass1()
}
class Subclass1 extends SuperClass {
}
object Subclass2 extends SuperClass with MetaClass[Subclass2] {
def newInstance = new Subclass2()
}
class Subclass2 extends SuperClass {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment