Please suggest appropriate design pattern

Hi,
In my method currently I have around 13 if statements, each if statement checks for the instance of a particular object and takes action accordingly. The code looks ugly with too many If statements. Is there any suggested patten which I can use to eliminate these if statements?.
Thanks in advance.

ams_z wrote:
Hi,
In my method currently I have around 13 if statements, each if statement checks for the instance of a particular object and takes action accordingly. The code looks ugly with too many If statements. Is there any suggested patten which I can use to eliminate these if statements?.If these are your own classes
have them implement an interface so the objects can perform the action themselves.
If they are predefined classes
write action methods that take each of them as argument
or write wrapper classes for them with an action method.

Similar Messages

  • Suggest what design pattern is applicable for my case

    I have an object called GrantAward , these awards I have to show to the user for selection
    1. I call a web service to get list of GrantAwards.
    2.for each GrantAward check if this is present in my database
    a. if not there insert
    3.for each GrantAward check some conditions
    a if satisfied add to the list to show to user
    b if not satisfied do not add to list .
    these are the steps involved before I can show the GrantAwards to user for selection , please suggest me what design pattern can I use ?

    I'm not sure you want to hunt for patterns when you already know what you are implementing. A lot of people have pattern fever. Patterns are useful constructs for communicating design ideas and enforcing best practices. But I rarely go out and hunt for a specific pattern (or name my objects after patterns). If you are doing a heavyweight methodology with RUP or something similar, I could see stereotyping your UML with patterns.
    That having been said, you already have a Facade with your service. You are undoubtedly using DataAccessObject to fetch your records. Your conditions could be implemented with a ChainOfResponsibility and/or Strategy pattern. What you return could be a Composite. Potentially the request and response are a Command. And your overall architecture could be MVC.
    But IMO that is overkill.
    - Saish

  • Can you suggest a Design pattern for moving a desktop app to  web?

    Hi,
    I have been asked to move a desktop applciaiton which has Serialized files as persistant layer in to Web, can anyone suggest me a good design pattern to accomplish this.

    I dont know what data is in the files, but I suggest looking at creating a set of database tables, normalize them, and copying the data to the tables (via java). Have a DBA review your database schema design if possible before copying the data. Then, use MVC design as I describe here:
    http://forums.sun.com/thread.jspa?messageID=10786901
    Once you get experience in the MVC design described above, your next project can use MVC with a framework such as Java Spring (a more advanced topic). You should read a book cover on Spring to cover on it first.

  • Please suggest me a suitable design pattern for the scenario below

    Hello,
    I have around three to four methods in a class. And their invocation is mutually exclusive that only one of them can be called depending upon the scenario. usually to acheive this, what we do is, write if and else loops and depending upon the scenario, we call the method correspondingly. i thought of avoiding this if else loops and would like to know whether there is any possibility for achieving the same without if else loops? if yes how do we do this? is there any design pattern available?
    Thanks, Aravinth

    Hi,
    In java we have something is called reflection; reflection is very powerful API. I would suggest the below to start with
    public class Foo {
         public static final String METHOD_ONE="methodOne";
         public static final String METHOD_TWO="methodTwo";
         public void methodOne() {
              System.out.println("method one is being invoked..");
         public void methodTwo() {
              System.out.println("method two is being invoked..");
         public void methodInvoker(String scenario) throws Exception {
              Class clazz =this.getClass();     
              Method method =clazz.getMethod(scenario, new Class[]{} );
              method.invoke(this, new Object[]{});
         public static void main(String args[] ) throws Exception  {
              Foo foo = new Foo();
              foo.methodInvoker(Foo.METHOD_ONE);
              foo.methodInvoker(Foo.METHOD_TWO);
         }I hope this could help
    Regards,
    Alan Mehio

  • Suggest good book for J2EE Design Pattern.

    Is there any good book for J2EE Design pattern? I know Head First Design Pattern book, but is focuses oncore java. I want to learn in detail with examples J2EE design pattern.
    Please suggest good books.
    Thanks in advance.
    Rahul.

    most j2ee patterns are discredited now. they were mostly workarounds for deficiencies in ejb 1 & 2 specs.
    "core j2ee patterns" is your best bet, but take it with a grain of salt.
    better to learn spring, IMO:
    springframework.org
    %

  • Please Suggest on this(Query Designer)

    Hi ALL,
       I want to design reports from one Query as shown below other
              Cost of setup
                 (In US$)
    Items                  Market Price       Discount        
    Construction cost     10                    8                    
    Building cost            20                   18
    Land Cost                30                   28
    Material Cost            40                  38
    Total                      100                   90
              Cost of setup
                 (In INR )
    Items                  Market Price       Discount        
    Construction cost     10                    8                    
    Building cost            20                   18
    Land Cost                30                   28
    Material Cost            40                  38
    Total                      100                   90     
    Please Suggest on this.
    Thanks & Regards
    Sameer Khan

    Hi ALL,
       I want to design reports from one Query as shown below other
              Cost of setup
                 (In US$)
    Items -
    Market Price----
    Discount        
    Construction cost----
         10   -
             8                    
    Building cost     -
            20   -
           18
    Land Cost         -
             30   -
          28
    Material Cost   -
            40   -
             38
    Total               -
            100   -
            90
              Cost of setup
                 (In INR )
      Items -
    Market Price----
    Discount        
    Construction cost----
         10   -
             8                    
    Building cost     -
            20   -
           18
    Land Cost         -
             30   -
          28
    Material Cost   -
            40   -
             38
    Total               -
            100   -
            90
    Please Suggest on this.
    Thanks & Regards
    Sameer Khan

  • Hi, i am using SAP by Design in india. I am trying to get GL entry report in which i require a field "Approved by" but unable to find - please suggest.

    Hi, i am using SAP by Design in india. I am trying to get GL entry report in which i require a field "Approved by" but unable to find - please suggest.

    Hi hanmant,
    You could find GL Line item report under General ledger WOC => Reports => List=> G/L Line Item Report, but this report does not have filter parameter "Approved by".
    May I know what was the use case behind "Approved by" field?
    BR, Rakesh

  • Struts using DAO Design Pattern ..?Please give an example..... URGENT......

    Dear all,
    I have to develop an application in Struts by using DAO design pattern ..........
    Please give an example on Struts using DAO...................
    Thank you
    Please

    I'm glad you asked. It means Read The Flaming Manual. That'd be the struts manual by the way.

  • Suggestions regarding corej2ee design patterns

    hi all
    i wanted to go through the core j2ee design pattern but i don't know which one to refer and what to
    so i need suggestions that what to read in a design pattern
    and which is the best book or pdf if possible send me the link too

    Core J2EE patterns are not what they were. A lot of them would be considered anti-patterns, work arounds for deficiencies in the EJB 1.0 and 2.0 specs that have been addressed in EJB 3.0.
    The "Core J2EE Patterns" (Amazon.com search will find it) sounds like what you want.
    %

  • Which Adaptor is appropriate please suggest

    Hi All,
    I have the following scenario and want your suggestions:
    A web based applicaiton (say A) to create customer need to integrate with another web based applicaiton (say B) which uses the customer details to display of Applicaiton A... wondering do I need to go for SOAP adaptor/HTTP adaptor or do I need to integrate these two applicaitons at data base level using JDBC adaptor?
    What are the steps/any documentation to get the data from web site to SAP PI when User clicks submit button?
    Please suggest.
    Thanks
    Rajeev

    >>> but my questtion is what needs to be done at Applicaiton A side to create Input and post the data in the SAP PI URL... As they are using the web client provided by the Application provider..Do they have to write code at the submit button of the web page? If so they have to customnise the code delivered by the provider? How it works.. Its been first time going through this...
    Yes, if you create webservice by creating soap sender and give WSDL, then they will have to write webservice client program in java or any language to access your webservice. This program will be called in their side at the time of hitting submit button of the web page.
    For this you have to go through soap sender sdn documents.
    or  As I already mentioned, create HTTP sender and provide your payload structure and url as we discussed in the above replies. A has to create coding to post HTTP using the url during submit hit button on their web page.
    >>Do they pass all the values in the URL or to the URL?
    This is client A's problem. Why do you worry?  There are plenty of documents to do http post.. The below coding is simple snippet..
    Search google for plenty of documents...
    try {
        // Construct data
        String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
        data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");
        // Send data
        URL url = new URL("http://hostname:80/cgi");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();
        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            // Process line...
        wr.close();
        rd.close();
    } catch (Exception e) {
    >>Is it possible to use SOAP adaptor instead of HTTP adaptor? so that I can use AAE in the entire scenario. Applicaiton A is a web client interface through which Customers are created.If I need to use HTTP Adaptor, do I need to create HTTP Sender Adaptor and sender Aggrement ?
    Yes, if you host webservice using soap sender adaptor. Already answered above ...
    >> If I need to use HTTP Adaptor, do I need to create HTTP Sender Adaptor and sender Aggrement ?
    no. Http adaptor is in abap stack. so you dont need sender agreement.

  • Need Suggestion for design

    Hi,
    My application is based on multiple forms. When user logged into application he has list of programs.
    Now each program has multiple forms which need to field step by step and at the last page it should save the data.
    So, right now as per our design we create bean for each form, each bean has at least 20 variables and generate their objects with session scope. When use exit from the last page we manually remove all the objects.
    Now the problem with this pattern is that we receive PemGenSpace error in every week.
    The reason is we use to store large object to session.
    Can you please suggest me a better solution to overcome this problem?
    Thanks.

    So let say if user is on 4th form now if he jumps to the 1st form we have to fetch it from the database that is also cost to performance.
    To save this cost we use to save the data into session.Which has its own cost, which is much higher, as your server stops working.
    It is futile to quibble about a database lookup or two when your cure is worse than the disease. You have to put the data somewhere else, that doesn't cost memory. In other words, the database.
    What we have here is premature optimization. Have you even measured what the cost of the extra lookups is?
    As per your suggestion if we save data to DB with auto commit false then are we able to retrieve those data from DB?Of course, as long as it's inside the same transaction.

  • Does any body have any design patterns of JSF Web Application Developping?

    Can any one answer me some questions?
    #1.I am an amatuar of people who develop Web Application.For some reason,We choose the JSF to develop our item.through some introduction,I know the UI component of JSF is resided in Server side,is it right?but I am a little confused that:if there are many users who are exploring our jsf website.(to simplify my question,image I had just one web page and just one button)How many UI components(buttons) will be there?How it(they?) works?
    #2.Does any body have the success experience (for example design pattern)to develop web applications?if We just concern about the Add,Delete,Modify,Query operations of some data.
    I just do my job according to my feeling.
    I will give every page a pagebean(backing bean),and I am not sure how to combine the business data with the pagebean.some one suggested that I should use delegate pattern to separate my business log and page logic.But I am still confused by following things:
    #2.1 does JSF have the same ability to help us construct the model dialog just like swing to
    help us control the operation flow?
    #2.2 If there is not,Does the following way work?I put every tabledata's property as corresponed component.if user choosed the row in the table,My Listener will syncronize the row data to the components.But
    #2.2.1 if JSF has the components according to the web users' number,how can My Listener tell which component should be update?Should I maintain the map?
    #2.2.2 If the problem I imaged above is false,Does any body can tell me how to custom      the ListDataModel,so I can use it like Swing?because now I can just use some view data to insert into ListDataModel,but after some selection operation,my business object must be find according to the selected data,it is not an interesting job!
         I am waiting for your advice!

    Ok I'll try to explain Step by step please correct me if I make any mistake because I have not played much with shared variables.
    To create a shared variable to an RT target go to the target if tou have already otherwise add an RT target by right clicking the Project>>Add targets and Devices
    Then in the target Right clikc and select the variable as shown below.
    Then once the Shared variable settings window opens Enter a variable name and then Select the type "Network Published"
    In the right side you can select the data type for the shared variable and even you can choose your custome controls.
    After selecting the data type go for the Network and select buffering if required else leave it if you are planning to use the variable just for display purpose.
    Then you can enable the RT FIFO if required (Not able to explain how it works and why it is used).
    Then after completing the Shared variable setup you can access the variable in the VI in both the Host and the RT.
    You can bind the variable to a control so that if any data from the RT is coming you can read the data from that control.
    Once you have placed your shared variable in the BD you can change the access typr to read or write depending on your need.
    This might not explain the complete shared variable concept but I believe that this would defenelty give you a kick off to start using the shared variable. Please correct or add more comments if anybody know better.
    Good luck.
    The best solution is the one you find it by yourself

  • I have a situation please suggest some transactional solution.

    hi,
        I have two databases one is entry database (DB1) Where entery is done, other database is reporting database (D2).
    we are trying to transfer data using stored procedure from db1 to db2. the  sp will be scheduled to run after every 20 to 30 sec.
    in db1 we keep three cols in all tables transferedcol, updatedcol, activecol.
    --activecol gets 1 if when record is entered first time and remain same while updation.
    this col gets 2 if deleted( we do not do physical deletion we only mark 2 in activecol and updagtedcol)
    --transferedcol gets 1 if not transfered to db2, if transfered to db2 then we put 0 in it.
    if record gets updated then it gets 1 again so that we can transfer it again.
    --updatedcol gets 0 for new entry of  each record and 1 if updated after transfer of the record to db2 else if any one tries to updated it before transfer then it will be 0 for new record , after the transfer of that record if some one updates the record
    then it gets 1 and remains 1 throught out the life . yes it gets 2 if record is deleted ( deletion is not  physical , it is logical by setting 2 in activecol and updatedcol).
    in db2 we have only required cols for reporting,  but if required we can keep some cols like transfered ,active and updated.
    this db2 has fk and table gets record from joins of many tables of db1 which also has  fks
    that is schema is not same.
    Q1) i want to transfer only the records having transfered col marked as 1 and after transfering i want to make them 0 from the stored procedure which runs after every 20 30 sec.
    please suggest some solution with isolation level.
    note: on db1 i want that entery should not be blocked to much and at the same it want stored procedure to transfer the data from db1 to db2 so that people can see the report at the very time.
    yours sincerley

        I have two databases one is entry database (DB1) Where entery is done, other database is reporting database (D2).
    we are trying to transfer data using stored procedure from db1 to db2. the  sp will be scheduled to run after every 20 to 30 sec.
    Have you considered replication?
    BOL: "SQL Server Replication
    Replication is a set of technologies for copying and distributing data and database objects from one database to another and then synchronizing between databases to maintain consistency. Using replication, you can distribute data to different locations and
    to remote or mobile users over local and wide area networks, dial-up connections, wireless connections, and the Internet.
    Transactional replication is typically used in server-to-server scenarios that require high throughput, including: improving scalability and availability; data warehousing and reporting; integrating data from multiple sites; integrating heterogeneous data;
    and offloading batch processing. Merge replication is primarily designed for mobile applications or distributed server applications that have possible data conflicts. Common scenarios include: exchanging data with mobile users; consumer point of sale (POS)
    applications; and integration of data from multiple sites. Snapshot replication is used to provide the initial data set for transactional and merge replication; it can also be used when complete refreshes of data are appropriate. With these three types of
    replication, SQL Server provides a powerful and flexible system for synchronizing data across your enterprise. Replication to SQLCE 3.5 and SQLCE 4.0 is supported on both Windows Server 2012 and Windows 8.
    As an alternative to replication, you can synchronize databases by using Microsoft Sync Framework. Sync Framework includes components and an intuitive and flexible API that make it easy to synchronize among SQL Server, SQL Server Express, SQL Server Compact,
    and SQL Azure databases. Sync Framework also includes classes that can be adapted to synchronize between a SQL Server database and any other database that is compatible with ADO.NET."
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Design pattern

    Hi all
    I am developing a enterprise application using Struts 1.2,Spring 2.0 and Hibernate 3.0.Now i am concentrating in design pattern of my application. I read many article, there I Could find many pattern like session facade, business delegate, service locator, layered pattern ,etc. I came to know that business delegate and session facade are useful for EJB based application with distributed environment. My application does not need distributed environment. I have a plan to implement design pattern as follows
    Presentation layer -Struts
    Data Transfer object or Value object -with support from Struts form Bean
    Business layer - Spring ,Transaction management with spring AOP ,
    Persistence layer -Hibernate with spring support.
    Service locator - implemented by Spring application context file.
    IN the above, layers orders may change, pls ignore that.
    Please suggest ,it is a correct design or any enhancement can be given to this pattern.
    Any with relevant examples are really appreciated
    Thanks in advance

    For Data Access layer you will be having a Query or stored procedure defined which will be in Sync with your Orchestration . So whenever there is request coming from UI you need to call this Orchestration through schema or Orchestration exposed as web service.
    So there are two pointers.
    1) consume your Query or Stored procedure inside your Orchestration (with WCF SQL or WCF Oracle adapter). various articles exist to implement it
    http://msdn.microsoft.com/en-us/library/dd787968.aspx
    http://btsguru.blogspot.in/2011/08/wcf-sql-adapter-stored-procedure.html
    2) Once done you can expose your request response schema as web service
    http://msdn.microsoft.com/en-us/library/bb246047.aspx
    Thanks
    Abhishek

  • Design Patterns w/o EJB

    Greetings, I am attempting to build a JSF application while learning JSR 127 and a few of the J2EE design patterns. The problem that I am having is that I don't plan on using EJB/Spring with my project and many of the tutorials I have been able to find place a focus on the EJB/Spring implementation details which are both overkill for this project. That said, I want to learn the appropriate patterns to build a functional application without catching "pattern fever".
    I have a general idea of some of the patterns I need to use to get from the presentation tier to the data tier, such as Business Delegate and Data Transfer Object. However, I'm not sure I understand how to use these in conjunction with the managed beans facility. Do the managed beans contain (as in composition) the Business Delegate objects? Or do I use a DTO to push the data from the managed bean to the Delegate? How much if any logic do I put in the managed beans if I'm using them in this fashion (or are they basically just fields and getter/setters)?
    All comments or suggestions are sincerely appreciated,
    Jon

    Hi,
    Have you taken a look at Java BluePrints Solutions Catalog:
    https://blueprints.dev.java.net/bpcatalog/
    The Solutions Catalog focuses on different topics specifically so that you can pick and choose which articles are most interesting to you.
    -Larry

Maybe you are looking for

  • Can i Use two qery hints in one SQL(Oracle)?

    Hi, Can i Use two Query hints in one SQL(Oracle)? USE_HASH and No_Merge Thanks

  • X very sluggish during disk activity...

    Hi, Recently, X has become very sluggish when disk activity is taking place. It doesn't seem to matter if it's a read or write operation. The pointer freezes and judders across the screen and everything basically stops until the disk access is finish

  • Multiple Leopard Servers - DNS Setup

    Hi guys, Just wandering what I need to do when setting up more than one server on the network with my DNS settings. I already have a leopard server box, running advanced with DNS setup and working correctly. How do I setup the second server? Do I cre

  • My line/broadband history

    For some guys, I thought I would copy raymie67 and make a post and keep you all up-to-date about what has happened over the time of my faults: And now whats happening is we had 6 vans out last week and they think the underground cable has been struck

  • Default values 0000, changes to 0 in the excel sheet..How to Avoid?

    Hi, We have created a WebADI where we are defaulting a value 0000, but when we create the document..the default value changes to 0.. Please help Thanks in advance ramanathan