Let's say I have an entry point to my application, and it's a main() procedure in class A. The class A does some work, creates an instance of class B, and the instance of B does some work and creates an instance of class C, and so on... D, E, F, until some class K. Basically, I'm about 10 classes down in a fairly complex program (K or 10 is fairly arbitrary as this is a theoretical question but that would probably be fairly realistic in any case). Inside K, I need to finally parse command line arguments which are now required for K to know what it has to do. Say, for instance, that K does some configuration, but how it does its configuration is dependent on the values of passed-in command line arguments at the executable level (top level).
What are my options for getting my command line argument information from A down to K? Just to provide some context, I'm talking about object-oriented language design. If it helps, you can use one of the C-based languages as a structural reference.
If I pass them unmodified via the constructors from B to K, then everything from B (ie., A+1) to J (ie., K-1) serves only as a messenger for data (depends on / moves data that it doesn't care about at all) and is therefore coupled to this data.
I can also use a class which is statically initialized / has static variables which map to the command line arguments. Say, command line argument parser, ArgParser. This would make it so that only K is tied to the data, nothing else.
Any other suggestions? Does anyone have any knowledge or know of any books which talk about this specific problem?
Thanks.
What are my options for getting my command line argument information from A down to K? Just to provide some context, I'm talking about object-oriented language design. If it helps, you can use one of the C-based languages as a structural reference.
If I pass them unmodified via the constructors from B to K, then everything from B (ie., A+1) to J (ie., K-1) serves only as a messenger for data (depends on / moves data that it doesn't care about at all) and is therefore coupled to this data.
Code:
class A
{
public int main(argc, argv)
{
// do something
B* obj = new B(...);
obj->execute();
}
};
class B
{
public void execute ()
{
// do something
C* obj = new C(...);
obj->execute();
}
};
...
class K
{
public void execute ()
{
// wants to parse command line arguments and use them to do something
}
};
I can also use a class which is statically initialized / has static variables which map to the command line arguments. Say, command line argument parser, ArgParser. This would make it so that only K is tied to the data, nothing else.
Code:
class ArgParser
{
public static int getValue (const char* key);
public static void setValue (const char* key, int value);
};
class K
{
public void execute ()
{
int x = ArgParser::getValue("arg1");
// do something with the value
}
};
Any other suggestions? Does anyone have any knowledge or know of any books which talk about this specific problem?
Thanks.
Last edited: