Re: I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- From: Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@xxxxxxxxxxxxxxxx>
- Date: Tue, 29 Apr 2008 19:03:03 +0200
ZeldorBlat schreef:
On Apr 29, 9:43 am, Captain Paralytic <paul_laut...@xxxxxxxxx> wrote:Wow, I never realised you could do Hello World without instantiating a
custom class.
You mean like this?
public interface MessageStrategy {
public void sendMessage();
}
public abstract class AbstractStrategyFactory {
public abstract MessageStrategy createStrategy(MessageBody mb);
}
public class MessageBody {
Object payload;
public Object getPayload() {
return payload;
}
public void configure(Object obj) {
payload = obj;
}
public void send(MessageStrategy ms) {
ms.sendMessage();
}
}
public class DefaultFactory extends AbstractStrategyFactory {
private DefaultFactory() {}
static DefaultFactory instance;
public static AbstractStrategyFactory getInstance() {
if (null==instance)
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(obj.toString());
}
};
}
}
public class HelloWorld {
public static void main(String[] args) {
MessageBody mb = new MessageBody();
mb.configure("Hello World!");
AbstractStrategyFactory asf = DefaultFactory.getInstance();
MessageStrategy strategy = asf.createStrategy(mb);
mb.send(strategy);
}
}
LOL.
;-)
Good job. :P
Erwin Moller
.
- Follow-Ups:
- References:
- I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- From: tenxian
- Re: I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- From: ZeldorBlat
- Re: I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- From: Captain Paralytic
- Re: I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- From: ZeldorBlat
- I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- Prev by Date: Re: I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- Next by Date: Re: I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- Previous by thread: Re: I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- Next by thread: Re: I couldn't understand why PHP is so popular. The PHP code looks so horrible compared with Java.
- Index(es):