--------------------------------------------------------------------------------
interface MessageStrategy {
public void sendMessage();
}
--------------------------------------------------------------------------------
abstract class AbstractStrategyFactory {
public abstract MessageStrategy createStrategy(MessageBody mb);
}
class MessageBody {
Object payload;
public Object getPayload() { return payload; }
public void configure(Object obj) { payload = obj; }
public void send(MessageStrategy ms) { ms.sendMessage(); }
}
--------------------------------------------------------------------------------
class DefaultFactory extends AbstractStrategyFactory {
private DefaultFactory() {
;
}
static DefaultFactory instance;
public static AbstractStrategyFactory getInstance() {
if (instance == null)
instance = new DefaultFactory();
return instance;
}
public MessageStrategy createStrategy(final MessageBody mb) {
return new MessageStrategy() {
MessageBody body = mb;
public void sendMessage() {
Object obj = body.getPayload();
System.out.println((String) obj);
}
};
}
}
--------------------------------------------------------------------------------
class DefaultFactory extends AbstractStrategyFactory {
private DefaultFactory() {
;
}
static DefaultFactory instance;
public static AbstractStrategyFactory getInstance() {
if (instance == null)
instance = new DefaultFactory();
return instance;
}
public MessageStrategy createStrategy(final MessageBody mb) {
return new MessageStrategy() {
MessageBody body = mb;
public void sendMessage() {
Object obj = body.getPayload();
System.out.println((String) obj);
}
};
}
}
--------------------------------------------------------------------------------
Could you figure out what is the function of the above program? It's just a program to print a "hello world" to the console. Looking weird? This is what a pattern infected person can do, using them wrongly
Read the full thread of from the slashdot.org forum, over here.
No comments:
Post a Comment