I have a question regard design of my little IRC Framework, just for learning JAVA event and observer..
First question: http://en.wikipedia.org/wiki/Observer_pattern#Critics
The Observer pattern is criticized[6] for being too verbose, introducing too many bugs and violating software engineering principles, such as not promoting side-effects, encapsulation, composability, separation of concepts, scalability, uniformity, abstraction, resource management, semantic distance. The recommended approach is to gradually deprecate observers in favor of reactive programming abstractions.
I should use observer pattern in a production program, if is criticized and maybe deprected in future? java.util.observer is always a good choice?
Second question: I have two objects. Server and Channel
Server.java
public Server {
public Server () {
// Some stuff
channelList = new ArrayList<Channels>();
}
public Channel searchChannel(String channel) {
// Implements searching channel
}
public void parseMessage() {
if (someCondition1)
onEvent1();
elseif (someCondition2)
onEvent2();
}
public void onEvent1(String channel, String param) {
channel = searchChannel(channel);
channel.onEvent1(param);
}
public void onEvent2(String channel, String param) {
channel = searchChannel(channel);
channel.onEvent2(param);
}
}
** Channel.java**
public Channel {
public Channel(Server server) {
// Some stuff
this.server = server;
}
public void onEvent1(String channel, String param) {
// Stuff for Event1 fired from Server
server.responseAtEvent("blablabla");
}
public void onEvent2(String channel, String param) {
// Do stuff for Event2 from Server
server.responseAtEvent("blablabla");
}
In this case, in channel I have all method public and those are called from Server class... There is a better way to manage event handling? I thinking at ObserverPattern, but I guess it's more used in GUI stuff thus business logic class..
Cheers
I want to ask another thing regard Observer...
Why a lot of people dislike the JDK Observer pattern and suggest to implement your?
Why re-invent the wheel?
The re-implemented observer that I see is same observer of the JDK...