Skip to content

Instantly share code, notes, and snippets.

@sergiosvieira
Created May 27, 2013 13:59
Show Gist options
  • Save sergiosvieira/5657210 to your computer and use it in GitHub Desktop.
Save sergiosvieira/5657210 to your computer and use it in GitHub Desktop.
design patterns
public interface XMPPActions
{
public abstract void sendMessageWithBody(String text, String jid);
}
public class XMPPNormalActions implements XMPPActions
{
- void sendMessageWithBody(String text, String jid)
{
/** código relacionado ao envio de mensagem usando chat normal **/
System.out.println("Chat Normal");
}
}
public class XMPPMUCActions implements XMPPActions
{
void sendMessageWithBody(String text, String jid)
{
/** código relacionado ao envio de mensagem usando MUC **/
System.out.println("MUC Chat");
}
}
public class XMPPCore
{
void sendMessageWithBody(String text, String jid, XMPPActions action)
{
action.sendMessageWithBody(text, jid);
}
}
class ChatNormal {
public static void main(String[] args) {
XMPPCore core = new XMPPCore();
XMPPNormalActions action = new XMPPNormalActions();
core.sendMessageWithBody("aí dentro", "romulo@weelo.com", action);
}
}
class MUCChat {
public static void main(String[] args) {
XMPPCore core = new XMPPCore();
XMPPMUCActions action = new XMPPMUCActions();
core.sendMessageWithBody("aí dentro", "romulo@weelo.com", action);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment