Replace the Ifs using design Pattern

Hi guys,.

I have a class that receives an error code and define an associated error message. So, to avoid the nested ifs, I'm looking for a solution using the model maibe.

{if (returnCode.Equals("052"))}
Errors.Add ("error", new ActionError ("error.msg", applicationResources.getMessage ("errors.myerror52")));

{if (returnCode.Equals("055"))}
Errors.Add ("error", new ActionError ("error.msg", applicationResources.getMessage ("errors.myerro55")));

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

For each new error code and your respective message, I need to add a new one if in the class...

I accept some suggestions to do is better!

Thank you very much!

There are a number of approaches you could take. The validity and the relative value of some of them depend on the question whether the return code is really a string or a number formatted as a string. on the question of if you call always just errors.add (), just with different arguments, or if you need take completely different measures in some cases; on return codes how there; How often the codes will be added, changed, or deleted.

1. a code card--> object encapsulating the args to errors.add (back)

2. order model, which could be carried like a map of return code--> instance of a class that implements how to handle this code, or code return--> object class or class name, which then is instantiated, and the new run object. In both cases, the object that performs the processing will implement an interface that you define.

3. a table whose index is the code back and whose value is an object, the object class or name of the class that handles this particular code.

4. an enum with each enumeration value with either a different set of fields must be passed to errors.add () or a different implementation of a method, if you do not simply call errors.add () for each code.

5. a switch statement on the return code, such as an int or an enum, or, if you are on Java 7, as a string.

A little regardless of which of the above approaches you take, you must decide if you want to hard-code the code--> action, or if you want to put it in a configuration file or the database mapping.

Tags: Oracle

Similar Questions

  • replace the Cdata using updateXML

    XML is stored in an XMLTYPE COLUMN
    When I extracted the data before an update code looks like this:
    <gp:Script xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"><![CDATA[
    
                   GPSystem.trace("Entering OpenSecureChannel Script.");
                   
                   // Create a new Secure Channel 01 Protocol object *****************
                   var level = arguments[0];
                   GPSystem.trace("Level requested is "+level);
                   var sc = secureChannel;
                   GPSystem.trace("Secure Channel: "+sc);
                   GPSystem.trace("Attempting Initailize for Update.");
                   if(version == undefined)
                        version = 0;
                   GPSystem.trace("     initializeUpdate("+version+",0);");
                   response = new ByteString(sc.initializeUpdate(version, 0), HEX);
                   GPSystem.trace("Initialize for Update executed with response "+response);
                   if (response == null) {
                        throw new Error("Initialize Update command failed");
                   }
    
                   // Set the life cycle *********************************************
                   GPSystem.trace("Current secure channel state is "+sc.state);
                   switch (sc.state) {
                   case SC_CLOSE:
                        GPSystem.trace("Secure Channel state "+sc.state+" corresponds to SC_CLOSE");
                        break;
                   case SC_INITIALIZE:
                        GPSystem.trace("Secure Channel state "+sc.state+" corresponds to SC_INITIALIZE");
                        GPSystem.trace("Attempting to set the encryption key.");
                        GPSystem.trace("Key version = " + response.bytes(10,1));
                        if(true)//response.byteAt(10) == 0xFF)
                        {
                        GPSystem.trace("All keys values = "+key.ISK_M.getComponent(Key.DES));
                             sc.setEncKey(key.ISK_M);
                             sc.setMacKey(key.ISK_M);
                             sc.setDekKey(key.ISK_M);
                        }else
                             if(response.byteAt(10) >= 0x01)
                        {
                             GPSystem.trace("     setEncKey("+key.KDCenc.getComponent(Key.DES)+");");
                             sc.setEncKey(key.KDCenc);
                             GPSystem.trace("Attempting to set the MAC key.");
                             GPSystem.trace("     setMacKey("+key.KDCmac.getComponent(Key.DES)+");");
                             sc.setMacKey(key.KDCmac);
                             GPSystem.trace("Attempting to set the key exchange key.");
                             GPSystem.trace("     setDekKey("+key.KDCkek.getComponent(Key.DES)+");");
                             sc.setDekKey(key.KDCkek);
                        }
    
                        break;
                   case SC_OPEN:
                        GPSystem.trace("Secure Channel state "+sc.state+" corresponds to SC_OPEN");
                        break;
                   default:
                        GPSystem.trace("Secure Channel state "+sc.state+" corresponds to an unrecognized state");
                        Throw("Card is in an unrecognized state");
                        break;
                   }
    
                   // Perform an External Authenticate *******************************
                   GPSystem.trace("Attempting External Authenticate.");
                   GPSystem.trace("     externalAuthenticate("+level+");");
                   sc.externalAuthenticate(level);
                   GPSystem.trace("SecureChannel has been opened");
                   ]]></gp:Script>
    I run the update as follows
    update ci_profile
       set profile_text_xml = updateXML(profile_text_xml,
                                     '/ApplicationProfile/SecureChannel/OpenSecureChannel','/gp:Script<![CDATA[
    
                   GPSystem.trace("Entering OpenSecureChannel Script.");
                   THIS IS MY TEST 
                   // Create a new Secure Channel 01 Protocol object *****************
                   var level = arguments[0];
                   GPSystem.trace("Level requested is "+level);
                   var sc = secureChannel;
                   GPSystem.trace("Secure Channel: "+sc);
                   GPSystem.trace("Attempting Initailize for Update.");
                   if(version == undefined)
                        version = 0;
                   GPSystem.trace("     initializeUpdate("+version+",0);");
                   response = new ByteString(sc.initializeUpdate(version, 0), HEX);
                   GPSystem.trace("Initialize for Update executed with response "+response);
                   if (response == null) {
                        throw new Error("Initialize Update command failed");
                   }
    
                   // Set the life cycle *********************************************
                   GPSystem.trace("Current secure channel state is "+sc.state);
                   switch (sc.state) {
                   case SC_CLOSE:
                        GPSystem.trace("Secure Channel state "+sc.state+" corresponds to SC_CLOSE");
                        break;
                   case SC_INITIALIZE:
                        GPSystem.trace("Secure Channel state "+sc.state+" corresponds to SC_INITIALIZE");
                        GPSystem.trace("Attempting to set the encryption key.");
                        GPSystem.trace("Key version = " + response.bytes(10,1));
                        if(true)//response.byteAt(10) == 0xFF)
                        {
                        GPSystem.trace("All keys values = "+key.ISK_M.getComponent(Key.DES));
                             sc.setEncKey(key.ISK_M);
                             sc.setMacKey(key.ISK_M);
                             sc.setDekKey(key.ISK_M);
                        }else
                             if(response.byteAt(10) >= 0x01)
                        {
                             GPSystem.trace("     setEncKey("+key.KDCenc.getComponent(Key.DES)+");");
                             sc.setEncKey(key.KDCenc);
                             GPSystem.trace("Attempting to set the MAC key.");
                             GPSystem.trace("     setMacKey("+key.KDCmac.getComponent(Key.DES)+");");
                             sc.setMacKey(key.KDCmac);
                             GPSystem.trace("Attempting to set the key exchange key.");
                             GPSystem.trace("     setDekKey("+key.KDCkek.getComponent(Key.DES)+");");
                             sc.setDekKey(key.KDCkek);
                        }
    
                        break;
                   case SC_OPEN:
                        GPSystem.trace("Secure Channel state "+sc.state+" corresponds to SC_OPEN");
                        break;
                   default:
                        GPSystem.trace("Secure Channel state "+sc.state+" corresponds to an unrecognized state");
                        Throw("Card is in an unrecognized state");
                        break;
                   }
    
                   // Perform an External Authenticate *******************************
                   GPSystem.trace("Attempting External Authenticate.");
                   GPSystem.trace("     externalAuthenticate("+level+");");
                   sc.externalAuthenticate(level);
                   GPSystem.trace("SecureChannel has been opened");
                   ]]>',
                                   'xmlns="http://namespaces.globalplatform.org/systems-profiles/1.1.0"'
     )
    where profile_id = '2A864886FC6B640103'
    and existsnode(profile_text_xml,'/ApplicationProfile/SecureChannel/OpenSecureChannel/Script','xmlns="http://namespaces.globalplatform.org/systems-profiles/1.1.0"')=1
    Now, all I'm doing here is to replace the! CDATA section so I'm just copy the original section and replace as well as 'The PRESENT IS MY ESSAY' on the inside.

    I see that I lose the format from the beginning of the tag. Pointers to where I'm wrong here?

    Hello

    in the update clause ' / gp: Script '.

    try to update the value of gp: Script only using text()

    Update ci_profile
    Set profile_text_xml = updateXML (profile_text_xml,
    ' / ApplicationProfile, SecureChannel, OpenSecureChannel, Script / text () ',' '
    'xmlns = "http://namespaces.globalplatform.org/systems-profiles/1.1.0" ')
    where the...

    Ants

  • Replace the Image using different directory

    6.6.1 OSX 10.11.3's speech

    How to replace a picture of presentation with another image that lives outside of iPhoto?

    I see no possibility to browse other directories outside of what is already within iPhoto. If this is the case, then this is terribly limited. I'm working on a project I'll replace a lot of images with and I don't want to drop them or use iPhoto to do this.

    Thank you!

    Any help would be appreciated, if there is a way to directly access the iPhoto directory via the Finder that would work too.

  • Replace the sky using only lightroom?

    Anyone know how to take a picture view of the sky and add it to another photo in Lightroom? I found lots of tutorials online, but they all require you to have Photoshop, too.

    I have Lightroom, so I was wondering if anyone has the steps on how to replace a sky if you also do not have Photoshop.

    Cannot be done in Lightroom.

    You need to use Photoshop or Photoshop Elements.

  • What design pattern - the functionality of language change

    On my request, I will have a series of buttons to choose a language. When the user selects a language, all control labels, pop-up messages and other turns in the chosen language.

    I would like to do from a standpoint of OOP and use design patterns. That we recommend to use?

    My guess is the policy template. Am I wrong?

    Thanks for any comment or the link.

    The policy template is used to exchange algorithms dynamically. Based on user input, that a decision can be made to perform one or more functions (game of). This behavior is encapsulated in separate objects.

    You just want to Exchange data during execution. Or maybe set some behaviours about specific functions in languages like the currencies in the way which are managed, and the other measures. The latter would be applied as a reason for the shell.

    When it is simply data need changed/loaded during execution, it instead of a change to the model in the MVC design pattern, using an observer to notify all registered "headphones" and using a command to get the thing going.

  • example of façade design pattern?

    Can someone point me to an example of this OOP design LabVIEW? I learn OBJECT oriented programming in LabVIEW and my task is to create an example program using the façade design pattern. I can't find an example to study.

    I'm interested, too, so I posted a link to your question on the LAVA.  There, there are many discussions of this kind.

  • How to replace the image that contains clickable images?

    I use RoboHelp HTML 8. Some of my help topics have an image that contains several interactive images that allow the user to click to see, for example, the field or button definitions on objects on this image. In the past, I was able to grasp or to create a new image file and give it exactly the same name as the old image file (for example, ccm_assessment_shg.gif)-a new replacing the old. and when I saw the image in RoboHelp HTML, the new image contain still all image maps of the original image.

    However, now I see an image (.png) file in one of my subjects and I would like to replace it, but my old process 'replacement with the same name' does not seem to work. What is my problem? How can I do this in RoboHelp 8? Is the problem related to the file must be a gif instead of a png? (I must confess that it's been several months that I worked in RoboHelp, so I just forgot something. I can't find instructions on the use of image maps and self-help groups).

    Thanks a lot for all the good advice!

    Hello

    Exactly how you try to replace the image? I ask, because if you open the dialog box Image and work this way, you will probably lose the connection with the regions of image maps. My preferred method is to simply work completely behind RoboHelp back by replacing the image using Windows Explorer. RoboHelp should be none the wiser as long as the file name and location are the same.

    See you soon... Rick

    Useful and practical links

    Wish to RoboHelp form/Bug report form

    Begin to learn RoboHelp HTML 7, 8 or 9 in the day!

    Adobe Certified RoboHelp HTML Training

    SorcerStone blog

    RoboHelp EBooks

  • Action to replace the contents of a smart object

    I use CS5/PS to create a collage created multiple images (smart object layers) that I've positioned using clipping masks.

    I would like to be able to replace the content of the images, which I can do via layer > smart objects > replace contents..., but I would like to have an action for a process of 'one-click' instead of three clicks.  Problem is, when I try to record the action, it forces me to complete replacement, and then the action gets wired to replace the image used in the 'record' action and therefore does not allow me to select which image I'd like to use.

    This feature is available in PS Elements, so I think it's possible.  I don't know that miss me something pretty basic, I do not know what!

    Thanks in advance,

    Brian

    «Separate forums Photoshop Windows and Macintosh will become read-only on Tuesday, January 3«»

    "Have you checked the ' enable/disable/shut down dialog box"-checkbox next to the item in the Actions Panel.

  • Buffer could replace the queue in the design of producer/consumer model

    Hello

    I have a question to which the task of buffer to store the data and the queue is also of the same thing so we could use the inplace queue buffer in a design of producer/consumer model.

    No, these examples of buffer not almost equal to a queue, and never "replaces" queue at the producer/consumer.

    The advantage the most important of the queues for the producers/consumers (which none of the other mechanics buffer sharing), it is that it works activities to warn the reader that the data is available. So if you would simply replace the queue by mechanics of tampon too developed that you have attached to your last post, you will lose a large part of the object using producer/consumer.

    Thus, to compare the two mechanics:

    -Tail works activities, while the example of the buffer is not.

    -Tail must allocate memory during execution if several items are written in that corresponding queue. This also applies to the buffer (must be resized).

    -Given that the buffer is actually simply a table with overhead, memory management becomes slow and messy with the increase in fragmentation of memory. Queues to play much better here (but have their limitations, there also).

    -Overload of the buffer (the table manipulation) must be implemented manually. The queue functions encapsulate all the necessary features that you will need. So the queues have a simple API, while the buffer is not.

    -Given that the buffer is simply a table, you will have a hard time sharing the content in two parallel running loops. You will need to implement an additional charge using data value references to manage the buffer or lose a lot of memory using mechanics as variables. Lose the memory, you will probably encounter racing conditions so don't think not even on this subject.

    This led to four '+' for the queue and only a single point where 'buffer' is equal to the queue.

    Hopefully, this clears things up a bit.

    Norbert

  • Satellite A135: Vista will not start after replacing HARD drive using the recovery disk

    Toshiba Satellite A135-s7403 HARD drive failed, I have replaced the 80 GB with a WD Scorpio blue 250 GB hitachi. When I try to restore with recovery disk came with the laptop, it passes through two discs 1 and 2 and starts with the start-up of windows for the first time and then runs to the greenish with the spinner blue screen please wait... thne black screens for a second or 2 and then back to spinner, please wait and then it appears the box "installation of windows could not configure windows to run on hardware. This computer' only option is to click OK.

    Where to click ok, you get an another msg that says "windows could not complete the installation, install reinstall windows. I tried like 50 times now. Startup Repair indicates the root = failure cause while the installation program is underway. I know that my drive are good, as I adjusted used then about a month when I upgraded the memory because the original memory 512 MB was not enough o well running vista.

    Hello
    To be honest I n don't know what the problem is there but can you get the original installation disc of Microsoft and try to install the OS, just to see if the OS installation will complete successfully?

  • Is it possible (or useful) to replace the processor in my HP Pavilion Elite m9060n...

    Is it possible (or useful) to replace the processor in my media library of Rikouman Pavilion Elite m9060n PC... There an IPIBL-(Berkeley) motherboard with Intel Chipset G33. Intel Core 2 Quad Logo running up to 2.4 GHz. is there a processor more fast which will be taken in the Socket 775 and improve the operating speed? It is economically interesting if possible? Would be very happy comments from some computer guru, as I'm obviously a novice.

    Morrismomic, welcome to the forum.

    The existing processor is Quad core maximum that you can use.  Your only choice is the Core 2 Duo E6700 or E6850:

    http://support.HP.com/us-en/document/c01197633

    Personally, I'm not sure you'll see an appreciable performance gain with either.  The memory and the video card are major concerns, too.  The system is as strong as its weakest component.

    If your problem is solved, please click "accept as a Solution.

  • I have the network wireless with an extreme airport using my base station that dessert 4 Airport expresses. I want to replace the base station with a time capsule from apple.  Are there specific instructions other that connect the new time capsule

    I have a wired to the internet using my base station for 4 expresses the hard extreme airport.  I want to replace the base station with a time capsule.

    It is also easy to replace the existing base station and adding the name of the network and the password?

    You should be able to transfer your configuration of your current access point to new, and then you would just set up the internal drive, try to look at these articles:

    ith-new http://www.TechRepublic.com/article/apples-Airport-extreme-out-with-the-old-in-w.

    -one-airport-extreme-or-time-capsule-to-http://www.iclarified.com/31189/How-to-Transfer-Your-configuration-settings-fromanother

  • How to replace the units of a channel using scripts % 3F

    Hello

    I have a few questions about the manipulation of the channel property 'unit' by scripts.

    Case 1: If the unit in the chain is not specified in the properties, what command should be used to add the inside unit?

    Case 2: When I create using the string ' Call.Root.ChannelGroups (1). Channels.Add ("name", DataTypeFloat64, 1)', empty space of unity being, what other command can be used which was available to the units to the breast?

    Case 3: Consider that I have channel (channel A) with the already defined unit (x), how can I replace the unit with another (y)? (Units of x and there belong to different physical quantities, so the ChnUnitConvert)

    Pls let me know if you nee details on the same.

    Kind regards

    Fazil Shah.

    Hi Fazil,

    The key word for SCRIPT DIAdem units is "unit_string". If you open the SCRIPT and open the channel property list you can select the property unit and drag & drop it in the SCRIPT Editor. This creates the code of script for the property.

    Case 1
    You have the options of towing: a quallified assignment complete or a channel object variable (if you have more settings for the channel of the second alternative is better)

    Data.Root.ChannelGroups (1). Channels ("mychannel"). Properties ("unit_string"). Value = "MyUnit.

    or

    Dim oChn
    Set oChn = Data.Root.ChannelGroups (x). Channels ("mychannel")
    oChn.Properties ("unit_string"). Value = "MyUnit.

    case 2
    You must add the unit after the creation of the channel

    Set oChn = Data.Root.ChannelGroups (x). Channels.Add ("MyChannel", DataTypeChnFloat64)
    oChn.Properties ("unit_string"). Value = "MyUnit.

    case 3
    It's the same as case 1 or if you do not want to use an already existing channel device, it can look like this

    oChnA.Properties ("unit_string"). Value = oChnB.Properties ("unit_string"). Value

    I hope that answers your questions

    Greetings

    Walter

  • HP Pavilion 14-b017cl: follow-up on creating and using the USB key recovery to win 8 after replacing the bad hard drive

    I have 2 hp pavillion sleekbook model 14-b017cl'. I replaced the hard drive in my son after that she doesn't have the "optimized hard drive dst test '. I used my sleekbook work to create a USB stick recovery. I followed the instructions to use the recovery to Win 8 usb drive. When I started the laptop of my son, with the USB stick inserted, I got this message.

    PXE - m0f: exit pxe rom

    no bootable device-insert bootdisk and press a key

    Flash player Flash when I put under tension. I rebooted, you press F2, conducted an audit on the new hard drive, happened.

    Later, I inserted the recovery key in my laptop (that I used to create it) and it would not initialize to top. I checked the content to the flash drive and they seemed "Chargers", so it seems to be what I expected. It seems that the recovery USB STICK will not work if my own laptop dies. What I have to buy the HP flash drive, or I'm doing something wrong.

    Hi @gretschman7,

    Thank you for your query.

    I understand you are trying to perform a recovery from a USB flash drive, but you get the error "pxe - m0f: exit pxe rom.

    "no bootable device-insert bootdisk and press any".  You check the recovery media on your laptop as it is the same model and it seems fine.

    Looks like you may need to change the boot sequence. Here is a link to HP - performing a recovery system (Windows 8) HP computers that will help you.   Here is a link to a YouTube video which can also help:.  Performing a recovery of HP system on a laptop HP with Windows 8.

    Please let me know the results.

    Thank you for your participation in the Forums of HP! We want to help you as well as others who may encounter a similar problem as you. Please consider tagging the post in order to solve your problem as "accept as Solution" to help other members of the community!

    To show recognition for my efforts please click the Thumbs Up below.

  • When you use quicklaunch to open a web page, if I already have an open page, how can I open a second page or pages using an icon from quick launch without closure or replacing the one I already opened?

    When you use quicklaunch to open a web page, if I already have an open page, how can I open a second page or pages using an icon from quick launch without closure or replacing the one I already opened?

    Hi Haubhaus,

    I know one thing to get your links to always open in a new window:
    1. Right-click on your desktop, select new, then shortcut
    2. Type "" C:\Program may Explorer\IEXPLORE. "." EXE" and click Next
    3. Name the shortcut (for example: Microsoft Home) and click Finish
    4. Right-click on the new shortcut and select Properties
    5. In the target box, arrow over until the end of the path, add a space and add -new (WEBSITEPATH). When your finished, your path should look like this:
      "" C:\Program may Explorer\IEXPLORE. "." "EXE" - new www.microsoft.com
    6. Click OK and try it!
    Let me know if it works or if I can be of further assistance!

    Cody C
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

Maybe you are looking for

  • I have a problem when trying to choose from the option menu bar

    I have problem with mozilla since the last update. When try to use one of the options from the menu bar, this appears: http://www.Dodaj.RS/f/1P/SL/1jR36iaa/Mozilla-Firefox-bug.PNG Also, I downloaded the video to show how my problem appears. http://ww

  • Satellite A300 - 25K - graphics upgrade possible?

    Hey there, Sorry I'm a n00b, so forgive me if it has been requested before. I have a+ Satellite A300, Dual Core T6400 @ 2 GHz +.my graphics is a+ ATI Mobility Radeon 3650 + and it is NOT ENOUGH... especially for the full HD video editing Q: + it woul

  • "... SHRegGetValueW not found in the library of dynamic links SHLWAPI.dll. »

    Message error "the procedure entry point SHRegGetValueW be found in the library of dynamic links SHLWAPI.dll". I get this error message after downloading it and pre-installation of IE 8.  Compared SHLWAPI found on HD with SHLWAPI on OS installation d

  • Registry Defender cleaner Cyber has stopped working

    How can I activate the cyber market Defender registry?

  • THE TIME CODE BASICS

    I am a newbie of timecode. We have a 2 photo with audio multitrack shoot all synchronized on timecode (no doubt!).What is the best why to start and compile a session?I have attached a screenshot in the clips of fusion menu, but it is all grayed out.