javascript - Prototyping in Java instead of extending -


is javascript-like prototyping anyhow achievable, using reflection? can wrap object inside one, extend functionality 1 or 2 more methods, without wiring original nonprivate methods wrapper class, or extends get?

if looking extension methods, try xtend. xtend language compiles java code , eliminates boilerplate code.

the following text stolen xtend docs extensions:

by adding extension keyword field, local variable or parameter declaration, instance methods become extension methods.

imagine want have layer specific functionality on class person. let in servlet-like class , want persist person using persistence mechanism. let assume person implements common interface entity. have following interface

interface entitypersistence {   public save(entity e);   public update(entity e);   public delete(entity e); } 

and if have obtained instance of type (through factory or dependency injection or ever) this:

class myservlet {   extension entitypersistence ep = factory.get(typeof(entitypersistence))   ...  } 

you able save, update , delete entity this:

val person person = ... person.save  // calls ep.save(person) person.name = 'horst' person.update  // calls ep.update(person) person.delete  // calls ep.delete(person) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -