473,651 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

command pattern variable number of parameters in execute method

oll3i
679 Contributor
i want to write a bank account programme and use a command pattern where execute method has variable number of parameters.


[code]
public interface Command {
public abstract void execute (String ... s);
}
[code]
how do i get the parameters passed to that method?
when is the execute method called?
Apr 14 '07 #1
14 6670
JosAH
11,448 Recognized Expert MVP
i want to write a bank account programme and use a command pattern where execute method has variable number of parameters.


Expand|Select|Wrap|Line Numbers
  1. public interface Command {
  2.      public abstract void execute (String ...  s);
  3. }
  4.  
how do i get the parameters passed to that method?
when is the execute method called?
You're in trouble here: other objects are not supposed to know anything at all
about an actual implementation of the Command interface so they don't know
how many Strings to pass to that particular implementation. All that the other
objects know is that they can pass zero or more Strings to your Command,
that's all. I think you have to go back to the drawing board for a bit more time.

kind regards,

Jos
Apr 14 '07 #2
oll3i
679 Contributor
so i'm not on a good path?
what's wrong with my Command?
Apr 14 '07 #3
JosAH
11,448 Recognized Expert MVP
so i'm not on a good path?
what's wrong with my Command?
That's what I wrote in my previous reply, but maybe things are not so bad.
What do these Strings mean? Can every Command take a variable number
of Strings or are the number of Strings depending on *which* Command is
to be executed?

kind regards,

Jos
Apr 14 '07 #4
oll3i
679 Contributor
the number of Strings is depending on which Command is
to be executed i think ?

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class WplacnaKonto implements Command { 
  3. // class for putting the money into account
  4. private Konto konto = new Konto();  // Account account = new Account();
  5.  
  6. public WplacnaKonto(Konto k){
  7.     konto=k;    
  8. }
  9.  
  10.  
  11. public void execute(String ... rozkaz){
  12.     double suma = Double.valueOf(rozkaz[0].trim()).doubleValue();
  13.      konto.wplata(suma); //account put the money  into account
  14. }
  15.  
  16. }
  17.  
this is a class responsible for putting the money into the account
i was following the example from this tutorial
http://www.javaworld.com/javaworld/j...68.html?page=1

kind regards
Apr 14 '07 #5
JosAH
11,448 Recognized Expert MVP
the number of Strings is depending on which Command is
to be executed i think ?
Then there's trouble ahead; suppose you have three different commands: A, B
and C all implementing your Command interface. Command A needs 2 Strings,
Command B needs 1 String and Command C needs 4 Strings. Your other
objects are not supposed to know which Command they're dealing with. How
should they know how many Strings to pass to a Command?

kind regards,

Jos
Apr 14 '07 #6
oll3i
679 Contributor
uups ... every Command can take a variable number
of Strings

public void execute(String ... rozkaz){
double suma = Double.valueOf( rozkaz[0].trim()).double Value();
konto.wplata(su ma);
}



putintoaccount. execute("100.00 ");
displayhistoryo faccounts.execu te("38102098765 43456","3810204 455667876");

and i dont know if am doing it right ?
Apr 14 '07 #7
JosAH
11,448 Recognized Expert MVP
uups ... every Command can take a variable number
of Strings

public void execute(String ... rozkaz){
double suma = Double.valueOf( rozkaz[0].trim()).double Value();
konto.wplata(su ma);
}



putintoaccount. execute("100.00 ");
displayhistoryo faccounts.execu te("38102098765 43456","3810204 455667876");

and i dont know if am doing it right ?
Not really because your scenario allows me to do this:
Expand|Select|Wrap|Line Numbers
  1. putintoaccount.execute("foo", "bar", "baz");
  2. displayhistoryofaccounts.execute("100.00", "-42", "Fido the Poodle");
In other words: I don't know to which Command I'm talking and I don't know
what to put as parameter values. All I know is that I'm talking to a Command
that takes zero or more Strings as its parameter list.

kind regards,

Jos
Apr 15 '07 #8
oll3i
679 Contributor
so what would you suggest me to do?
Apr 15 '07 #9
oll3i
679 Contributor
should i change my command execute method?
Apr 15 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11531
by: Cath B | last post by:
I am pretty sure I am getting a command timeout when execute a SQL procedure that has an output parameter. The code below is in an asp page that is called using RSGetASPObject. I want to be able to send a message back to the calling page to indicate that a timeout has occurred, but am having a hard time capturing the timeout error. I intend to set the timeout parameters so that I don't get timeout errors, but in the case that I would I...
5
4371
by: Bruno Alexandre | last post by:
Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under the recorset object.... how can I do this? I'm stuck here.
4
3086
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use the recordset to loop thru the recordset, update values from the recordset and then update the database by passing parmeters to another stored procedure. I would like to use the recordset object but can it be used to pass a parameter to a stored...
3
6122
by: Samuel R. Neff | last post by:
We're working on implementing a Command Pattern design with our application in order to help facilitate undo/redo. This is fine four user actions we control which basically means menu actions. However, it's not quite so clear for bound controls. We don't directly interact with the change--the user makes a change in a control, such as a grid, and the dataset stores the update. We haven't interjected any code which we can funnel through...
8
1710
by: Charles Law | last post by:
I am implementing the command pattern in VB.NET, where the commands have been serialised. That is, I have several classes that all inherit from my base Command class, that implements ICommand (standard stuff). The commands, however, are deserialised at runtime, so the idea of passing a receiver in the constructor does not work in this case. In addition, I am implementing the MacroCommand extension, and each command in a macro could...
4
2871
by: FluffyCat | last post by:
New on November 29, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Command Pattern. Since you all enjoyed the Visitor Pattern so much yesterday, today I have the Command Pattern for you. This one is pretty straight forward. In the Command Pattern an object encapsulates everything needed to execute a method in another object. http://www.fluffycat.com/SDCMSv2/PHP-Design-Patterns-Command/
34
11176
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a standard enum, so I wanted to know what you experts all thought. Is there a case for standard enums?
8
11679
by: Ben | last post by:
Hi! I already sent this to the ACCESS newsgroup. But since I do not know really which side is really causing the problem, I have decided to send this inquiry to this newsgroup also, if I may. Below is the environment of the application: a. MS Access 2003 application running on Windows XP b. SQL Server 2000 - backend running MS Server 2003 OS
1
2201
by: alexcpn | last post by:
Hi I have a Command class of type class Command { T* m_objptr; void (T::*method)(); : explicit Command(T* pObj,void (T::*p_method)(),long timeout,const
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.