Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

18
  • 19
    @DamithGanegoda Nope, if you read my code carefully you'll see it does exactly the same thing in that case. That's why there's no else between my two if statements, and why I'm assigning to data each time. If both flags are true, then compress() gets executed, then encrypt() gets executed on the result of compress(), just like you want. Commented Jan 1, 2016 at 15:37
  • 15
    @DavidPacker Technically, so does every if statement in every programming language. I went for simplicity, since this looked like a problem where a very simple answer was appropriate. Your solution is valid too, but personally I'd save it for when I have a lot more than two boolean flags to worry about. Commented Jan 1, 2016 at 15:55
  • 16
    @DavidPacker: correct is not defined by how well the code adheres to some guideline by some author about some programming ideology. Correct is "does the code do what it's supposed to do and was it implemented in a reasonable amount of time". If it makes sense to do it the "wrong way", then the wrong way is the right way because time is money. Commented Jan 1, 2016 at 18:56
  • 9
    @DavidPacker: If I was in the OP's position, and asked that question, Lightness Race in Orbit's comment is what I really need. "Finding a solution using design patterns" is already starting from the wrong foot. Commented Jan 1, 2016 at 19:18
  • 6
    @DavidPacker Actually if you read the question more closely, it doesn't insist on a pattern. It states, "I'm thinking about the Decorator pattern. Is it the right choice, or is there perhaps a better alternative?". You addressed the first sentence in my quote, but not the second. Other people took the approach that no, it is not the right choice. You can't then claim that only yours answers the question. Commented Jan 2, 2016 at 1:29