I am partially rewriting a java project in scala. For the persistence layer in the project I have a set of entities defined as interfaces with concrete implementations. I am rewriting the persistence layer with squeryl. I am trying to establish the most efficient way to bridge these types when calling the legacy code which will refer to these interfaces. So I have say in my legacy java code the following interface:
public interface Author
{
public void setName(String name);
public String getName();
// etc
}
void someLegacyFunc(Author author) // ...
And then in my new scala code I would have the following squeryl object
class Author (
val name: String;
// etc ...
)
I know I can bridge these two doing the following:
class AuthorBridge(author: Author) implemenets legacy.Author {
public void setName(String: name) = author.name = name
public String getName() = author.name
// etc.
}
However it is a very large library and I would like to avoid having to define a whole new set of bridge objects if possible. I am wondering if scala reflection might provide some more dynamic way of doing this along the following lines:
object Bridge {
def get[Legacy, Entity](entity: Entity): Legacy {
// builds an anonymous implementation of Legacy
// binding all the getter/setter methods to the entity's attributes
}
}
val legacyAuthor = getAuthor(author)
Thanks Des