Friday, September 4, 2009

Separated Interface

Defines an interface in a separate package from its implementation.

1. You can put interfaces in the same package as that of the client.

2. Or put interfaces in a third package.

Now, how does the client instantiate the implementation as this would require knowledge of the implementation class. There are two approaches for this

1. Use a separate factory object, where again there is a separated interface for the factory. And to bind an implementation to the factory, Plugin can be used.

2. Let yet another package that knows both the interface and implementation and it instantiates the right objects at startup.