Skip to main content
deleted 29 characters in body
Source Link
Martin Wickman
  • 13.4k
  • 3
  • 34
  • 66

Some ideas:

  • The usual approach in cases like this (looks like Command pattern to meCommand patternish) is passing additional parameters in the constructor. In your case, that means adding otherArgument to B during construction.

  • Turning the logic around might open up some options. For instance moving doStuff to AParams:

      for (String arg : listOfArgs) {
          AParams p = AParams.create(arg, otherArgument));
          for (A a : listOfA) {
              p.doStuff(a); // Let AParams to the lifting depending on type of A
          }
      }
    
  • Alternatively you can swallow your pride and check with instanceof in the loop and set otherArgument manually before calling doStuff.

If the above is not possible, then you have no choice except doing what you're doing (broadening the parameter argument). Don't overanalyze this stuff.

Some ideas:

  • The usual approach in cases like this (looks like Command pattern to me) is passing additional parameters in the constructor. In your case, that means adding otherArgument to B during construction.

  • Turning the logic around might open up some options. For instance moving doStuff to AParams:

      for (String arg : listOfArgs) {
          AParams p = AParams.create(arg, otherArgument));
          for (A a : listOfA) {
              p.doStuff(a); // Let AParams to the lifting depending on type of A
          }
      }
    
  • Alternatively you can swallow your pride and check with instanceof in the loop and set otherArgument manually before calling doStuff.

If the above is not possible, then you have no choice except doing what you're doing (broadening the parameter argument). Don't overanalyze this stuff.

  • The usual approach in cases like this (Command patternish) is passing additional parameters in the constructor. In your case, that means adding otherArgument to B during construction.

  • Turning the logic around might open up some options. For instance moving doStuff to AParams:

      for (String arg : listOfArgs) {
          AParams p = AParams.create(arg, otherArgument));
          for (A a : listOfA) {
              p.doStuff(a); // Let AParams to the lifting depending on type of A
          }
      }
    
  • Alternatively you can swallow your pride and check with instanceof in the loop and set otherArgument manually before calling doStuff.

If the above is not possible, then you have no choice except doing what you're doing (broadening the parameter argument). Don't overanalyze this stuff.

added 35 characters in body
Source Link
Martin Wickman
  • 13.4k
  • 3
  • 34
  • 66

Some ideas:

The usual approach in cases like this (looks like Command pattern to me) is passing additional parameters in the constructor. In your case, that means adding otherArgument to B during construction.

Turning the logic around might open up some options. For instance moving doStuff to AParams:

for (String arg : listOfArgs) {
    AParams p = AParams.create(arg, otherArgument));
    for (A a : listOfA) {
        p.doStuff(a); // Let AParams to the lifting depending on type of A
    }
}

Alternatively you can swallow your pride and check with instanceof in the loop and set otherArgument manually before calling doStuff.

  • The usual approach in cases like this (looks like Command pattern to me) is passing additional parameters in the constructor. In your case, that means adding otherArgument to B during construction.

  • Turning the logic around might open up some options. For instance moving doStuff to AParams:

      for (String arg : listOfArgs) {
          AParams p = AParams.create(arg, otherArgument));
          for (A a : listOfA) {
              p.doStuff(a); // Let AParams to the lifting depending on type of A
          }
      }
    
  • Alternatively you can swallow your pride and check with instanceof in the loop and set otherArgument manually before calling doStuff.

If that'sthe above is not possible, then you have no choice except doing what you're doing (broadening the parameter argument). Don't overanalyze this stuff.

Some ideas:

The usual approach in cases like this (looks like Command pattern to me) is passing additional parameters in the constructor. In your case, that means adding otherArgument to B during construction.

Turning the logic around might open up some options. For instance moving doStuff to AParams:

for (String arg : listOfArgs) {
    AParams p = AParams.create(arg, otherArgument));
    for (A a : listOfA) {
        p.doStuff(a); // Let AParams to the lifting depending on type of A
    }
}

Alternatively you can swallow your pride and check with instanceof in the loop and set otherArgument manually before calling doStuff.

If that's not possible then you have no choice except doing what you're doing (broadening the parameter argument). Don't overanalyze this stuff.

Some ideas:

  • The usual approach in cases like this (looks like Command pattern to me) is passing additional parameters in the constructor. In your case, that means adding otherArgument to B during construction.

  • Turning the logic around might open up some options. For instance moving doStuff to AParams:

      for (String arg : listOfArgs) {
          AParams p = AParams.create(arg, otherArgument));
          for (A a : listOfA) {
              p.doStuff(a); // Let AParams to the lifting depending on type of A
          }
      }
    
  • Alternatively you can swallow your pride and check with instanceof in the loop and set otherArgument manually before calling doStuff.

If the above is not possible, then you have no choice except doing what you're doing (broadening the parameter argument). Don't overanalyze this stuff.

Source Link
Martin Wickman
  • 13.4k
  • 3
  • 34
  • 66

Some ideas:

The usual approach in cases like this (looks like Command pattern to me) is passing additional parameters in the constructor. In your case, that means adding otherArgument to B during construction.

Turning the logic around might open up some options. For instance moving doStuff to AParams:

for (String arg : listOfArgs) {
    AParams p = AParams.create(arg, otherArgument));
    for (A a : listOfA) {
        p.doStuff(a); // Let AParams to the lifting depending on type of A
    }
}

Alternatively you can swallow your pride and check with instanceof in the loop and set otherArgument manually before calling doStuff.

If that's not possible then you have no choice except doing what you're doing (broadening the parameter argument). Don't overanalyze this stuff.