Does this account for Delegate and Strategy ?

Can I say delegate and strategy both are used at the same time in the example below ?

I load a class through reflections and invoke a write method on that. Now this in turn may write in to a file or database depending on the class being loaded (className) and each class that can be used implements the interface MyInterface so I can simply call myInterfaceObject.write to write into the database, file or what so ever by loading a proper class.

Class myclass = Class.forName(className);

Constructor c = myclass.getConstructor(null);

MyInterface object = c.newInstance(null);

object.writeValue("Java");

TIA

[740 byte] By [SrikanthBasa] at [2007-10-2 8:07:08]
# 1

> Can I say delegate and strategy both are used at the

> same time in the example below ?

It is possible but is a questionable statement based on the code fragment you've posted. Structurally they can appear very similar, however delegation is a small part of strategy pattern. I would agree that the code fragment is using delegate and it is quite possible that the class containing the code shown may be using strategy. The capability of the composite class that indicates the Strategy pattern is being used is that the client class knows enough about the context to determine which delegate (strategy) to actually use.

MartinS.a at 2007-7-16 22:01:28 > top of Java-index,Other Topics,Patterns & OO Design...