V
vk02720
Hi,
I have different type of messages to be handled in my app. I wrote a
base class like
BaseHandler {
public boolean perform() {
}
}
I get a message with a String messageType.
Just to avoid making changes to the same file ( and intending to keep a
good design ), I subclass each specific message handler from
BaseHandler and override perform() for each message.
The issue is how to organize the classes properly.
For example, I have following function to return correct handler :
public BaseHandler getHandler(messageType) {
//return the correct Handler based on messageType
}
Which class should such function belong ?
Is this a normal way to solve such problem. It appears quite common!
Not sure if this conforms to any Design Pattern....
The code is in Java.
Please advise.
TIA
I have different type of messages to be handled in my app. I wrote a
base class like
BaseHandler {
public boolean perform() {
}
}
I get a message with a String messageType.
Just to avoid making changes to the same file ( and intending to keep a
good design ), I subclass each specific message handler from
BaseHandler and override perform() for each message.
The issue is how to organize the classes properly.
For example, I have following function to return correct handler :
public BaseHandler getHandler(messageType) {
//return the correct Handler based on messageType
}
Which class should such function belong ?
Is this a normal way to solve such problem. It appears quite common!
Not sure if this conforms to any Design Pattern....
The code is in Java.
Please advise.
TIA