|
|||||
|
|||||
Home
What is dimple?Dimple is a simple framework that allows you to implement interface(s) in a duck-typing way in pure Java. There are two typical senarios where one would want to use dimple:
Why wouldn't I just use the "implements" keyword?Normally you would (and you should). But there're two cases where you may not want to "implements":
How do I stub a Connection using dimple?Connection stub = Implementor.proxy(Connection.class, new Object(){ public PreparedStatement prepareStatement(){ return someStubOrMockPreparedStatement; } }); This way, you are stubbing the "prepareStatement()" method without worrying about any other methods. How do I intercept method in a Connection object?Suppose a legacy system has a proprietary way of releasing jdbc connection, dimple can be used to wrap it up nicely: final Connection realConn = ...;//wherever you get it from Connection intercepted = Implementor.proxy(Connection.class, new Object(){ public void close(){ ConnectionManager.releaseConnection(realConn); } }, realConn);//for anything undefined, delegate to realConn ... intercepted.close();//it actually calls ConnectionManager.releaseConnection(realConn); So I just need to make sure the method name is the same?The rules for the interceptor methods are:
|
|||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||