oop - Is it possible to do prototype-based programming in Scala? -


is possible prototype-based programming in scala?

i have disagree easy angel... scala objects not need classes (they still have type... not same). ok write

val martin = new {    val name = "martin"   val surname = "ring"   def age = calendar.getinstance.get(calendar.year) - 1986 } 

also structural typing can write functions these objects:

def printperson(person: { def name: string; def age: int }) =    println("%s (%d)".format(person.name, person.age)) 

you can call printperson(martin) , print out martin (25)

so no need classes or traits if want that.

however prototype-based programming still not supported language (imho) not possible clone , extend objects anonymous type. guess write functions that... require massive use of reflection , there no native lanugage support..


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -