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?
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. -
public interface Command {
-
public abstract void execute (String ... s);
-
}
-
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
so i'm not on a good path?
what's wrong with my Command?
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
the number of Strings is depending on which Command is
to be executed i think ? -
-
public class WplacnaKonto implements Command {
-
// class for putting the money into account
-
private Konto konto = new Konto(); // Account account = new Account();
-
-
public WplacnaKonto(Konto k){
-
konto=k;
-
}
-
-
-
public void execute(String ... rozkaz){
-
double suma = Double.valueOf(rozkaz[0].trim()).doubleValue();
-
konto.wplata(suma); //account put the money into account
-
}
-
-
}
-
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
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
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 ?
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: -
putintoaccount.execute("foo", "bar", "baz");
-
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
so what would you suggest me to do?
should i change my command execute method?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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...
|
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...
|
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...
| |
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/
|
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?
|
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
|
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
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
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
| |