Skip to main content
Tweeted twitter.com/StackProgrammer/status/684592368390123520
Post Reopened by Pieter B, Karl Bielefeldt, maple_shaft
Post Closed as "Duplicate" by gnat, CommunityBot

What is the good Is there a design pattern to remove the need to check for following scenarioflags?

I'm going to save some string payload in the database.But I've I have two global configurations encryption and compress.We:

  • encryption
  • compression

These can enablebe enabled or disabled using the configuration in a way that either only one of configthem is enabled, both are enabled or both of themare disabled.

My current implementation likeis this.:

if (encryptionEnable && !compressEnable) {   encrypt(data); } else if (!encryptionEnable && compressEnable) {   compress(data); } else if (encryptionEnable && compressEnable) {   encrypt(compress(data)); } else { data; } 

I'm thinking about the Decorator pattern.Please help me out find good design pattern to handle this. Is it the right choice, or is there perhaps a better alternative?

What is the good design pattern for following scenario?

I'm going to save some string payload in the database.But I've two global configurations encryption and compress.We can enable either of config or both of them.

My current implementation like this.

if(encryptionEnable && !compressEnable){ encrypt(data); } else if(!encryptionEnable && compressEnable){ compress(data); } else if(encryptionEnable && compressEnable){ encrypt(compress(data)); } else { data; } 

I'm thinking about the Decorator pattern.Please help me out find good design pattern to handle this.

Is there a design pattern to remove the need to check for flags?

I'm going to save some string payload in the database. I have two global configurations:

  • encryption
  • compression

These can be enabled or disabled using the configuration in a way that either only one of them is enabled, both are enabled or both are disabled.

My current implementation is this:

if (encryptionEnable && !compressEnable) {   encrypt(data); } else if (!encryptionEnable && compressEnable) {   compress(data); } else if (encryptionEnable && compressEnable) {   encrypt(compress(data)); } else { data; } 

I'm thinking about the Decorator pattern. Is it the right choice, or is there perhaps a better alternative?

Source Link

What is the good design pattern for following scenario?

I'm going to save some string payload in the database.But I've two global configurations encryption and compress.We can enable either of config or both of them.

My current implementation like this.

if(encryptionEnable && !compressEnable){ encrypt(data); } else if(!encryptionEnable && compressEnable){ compress(data); } else if(encryptionEnable && compressEnable){ encrypt(compress(data)); } else { data; } 

I'm thinking about the Decorator pattern.Please help me out find good design pattern to handle this.