The Artima Developer Community
Sponsored Link

Java Answers Forum
Polymorphism Problem

1 reply on 1 page. Most recent reply: Jun 10, 2002 3:23 PM by Thomas SMETS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
DAYO

Posts: 22
Nickname: done
Registered: Jun, 2002

Polymorphism Problem Posted: Jun 10, 2002 2:36 AM
Reply to this message Reply
Advertisement
//DYNAMIC BINDING
I am writing a JAVA(SWING/GUI) program that recognises certain commands.Users will enter command and the program executes the command.I want to be able to add commands in future.I have been able to do it with IF/ELSE statements and would like to do it using polymorhism so as to allow dynamic binding.Part of the code is shown below

private class commandhandler implements ActionListener
{ public void actionPerformed(ActionEvent event)
for(int start=0;start<end;start++)
{ String read=label2.getText();
COMMAND (Op1,Op2);
}
}
public void COMMAND(String COM1,String COM2)
{ if(COM1.equals("01"))
{ String copy1=label.getText();
}
else if(opcode.equals("02"))
{//DO SOMETHING
}


Somebody suggested the following but I don?t quite understand:
1. Build a class with the following methods:
String[] getFunctions ();
Object[] getFunctionParams (String function);
boolean accept(String functioncall,String[] args);
boolean execute (String funcall, String[] args);
2. You could then just recompile your class with updates that would be recognizable to your console under this framework, or you could do something like this.
public static void main (String[] args) {
MyProjectOperations = class.forName(args[0]).instanceOf();
}
I would appreciate if someome can tell me how to acchieve this. .
.


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Polymorphism Problem Posted: Jun 10, 2002 3:23 PM
Reply to this message Reply
It really depends the way you want to tackle the problem...
Give a look at the http://www.javacoder.net/patterns.jsp
I would consider many of the patterns if I were you :
_ PROTOTYPE
_ BUILDER
_ FLYWEIGHT
You have of course the COMMAND which should really serve your purpose ...

Thomas SMETS,
SCJP2 - Brussels

Flat View: This topic has 1 reply on 1 page
Topic: Reg Rhino Previous Topic   Next Topic Topic: Can you create multicast sockets in an applet?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use