Is it good habit to use "Instanceof"

Is good habit to use "Instanceof" for selection purpose. Below code will make it more clear.
public boolean entryAdd(Object obj) throws SQLException
     String sSQL="";
     if (obj instanceof cT )
         cTeacher oT = (cT)obj;
         sSQL = "INSERT INTO tblT VALUES(";
         sSQL = sSQL + String.valueOf(getNextID("TID","tblT"));
         sSQL = sSQL + ",'";
         sSQL = sSQL + oT.Name + "','";
         sSQL = sSQL + oT.Qualification + "','";
         sSQL = sSQL + oT.Description + "')";
     }else if(obj instanceof cS)
         cS oS = (cS)obj;
         sSQL = "INSERT INTO tblS VALUES(";
         sSQL = sSQL + String.valueOf(getNextID("SID","tblS"));
         sSQL = sSQL + ",'";
         sSQL = sSQL + oS.Name + "','";
         sSQL = sSQL + oS.Code + "','";
         sSQL = sSQL + oS.Description + "')";
     }elseif(.){...
     else
         return false;
     Statement oStmt = getStatement(EnumDBType.UPDATEABLE);
     oStmt.execute(sSQL);
     oStmt.close();
     return true;
    }Well, in C++ we have enum. Which can be given as arg. when function is called. So,it is easy for caller and for us to get only values we want in arg. But, in java, we don't have this kind of feature(excluding J1.5).
So, should I be using above method for identifying object and taking action. Or should I declare Interface with all the costants for all the classes which i expect and take int as an argument. and tell caller to send one of the constant declared in interface. And using switch statement I take action.one of the constant declared in interface.
So, I am looking for good programming method of doing above task.

But, don't
you think "UlrikaJ" way is more straight forward.
Please give your suggestion.Ulrika's method, simple having every SQLStorable is certainly a very good way in simple cases.
The only complaint I would have is that SQL is a different domain of knowledge than whatever it is that the storable class is supposed to be doing. Suppose it changed. Suppose you decided to use a different persistence mechanism. Would you add XMLStorable and RMIStorable and whatever else to every class in you system?
Double-dispatch addresses this problem, but at the cost of having one class with comprehensive knowledge of every other class in the system.
A more general solution would be to have each class be able to describe itself (either by implementing a Storable interface, with method that could tell a SQLStorer, an XMLStorer, or whatever, how to store it, or by using Annotation to save the same information).
Plus, although this is somewhat of topic, as a visitor from the Generics forum, I want to point out that using StringBuffers and string concatenation is distinctly old-hat. Going forward, you could writ:public String apply (CT ot) {
    return String.format("INSERT INTO tblT VALUES(%d, %s, %s, %s)",
                         getNextID("TID","tblT"),
                         ot.name,
                         ot.qualification,
                         ot.description);
}which is quite a bit cooler.

Similar Messages

  • Posting a goods Receipts by using 'BAPI_GOODSMVT_CREATE'

    Hi experts,
    For a Handling Unit number, im Posting a goods Receipts by using 'BAPI_GOODSMVT_CREATE'
    Im passing the below values to the BAPI, to create a Material document and transfer order.
    GOODSMVT_HEADER- PSTNG_DATE (System Date)
    GOODSMVT_HEADER - DOC_DATE (System date)
    GOODSMVT_HEADER- PR_UNAME (SY-NAME)
    GOODSMVT_CODE- GM_CODE ( 01)
    GOODSMVT_ITEM-MOVE_TYPE (Movement type): movement type '101'
    GOODSMVT_ITEM- DELIV_NUMB_TO_SEARCH (Delivery)
    GOODSMVT_ITEM-DELIV_ITEM_TO_SEARCH (Delivery item)
    GOODSMVT_ITEM-PLANT (Plant) VEPO- WERKS
    GOODSMVT_ITEM-STGE_LOC (Storage location) VEPO- LGORT
    GOODSMVT_ITEM-ENTRY_QNT (Quantity)
    GOODSMVT_ITEM-ENTRY_UOM (Unit of measure)
    GOODSMVT_ITEM-PO_NUMBER (Purchase order)
    GOODSMVT_ITEM-PO_ITEM (Purch. order item)
    GOODSMVT_ITEM-UNLOAD_PT ( HU number)
    GOODSMVT_ITEM-MVT_IND (Movement indicator) = 'B'
    I dont know what values has to be passed to the following fields in BAPI
    *GOODSMVT_ITEM-SU_PL_STCK_1*
    *GOODSMVT_ITEM-SU_PL_STCK_2*
    *GOODSMVT_ITEM-ST_UN_QTYY_1*
    *GOODSMVT_ITEM-ST_UN_QTYY_2*
    *GOODSMVT_ITEM-UNITTYPE_1*
    *GOODSMVT_ITEM-UNITTYPE_2*
    All those values has to be updated in the Material document.
    Please help me on this.
    Thanks & regards,
    Leo
    Edited by: Thomas Zloch on Nov 17, 2011 10:11 AM

    I konw that I'm digging an old thread but let's have a look. I have the same problrm (filling the DMBTR field from the BAPI). I have not tried yet but checking the code of the BAdI I found that the EXTENSIONIN_TO_MATDOC method of the MB_BAPI_GOODSMVT_CREATE BAdI is called before creating the material posting and it has the IMSEG table as changing parameter. I will give it a try soon. Hope that it will work.
    Has anyone experience with it by any chance?
    Adam

  • Copy data from a UDO form to Goods Receipt PO using UI API

    Hi, all
    I tried to copy data from a UDO form to Goods Receipt PO using UI API through following codes.
    It works fine while copying to a Item-type Goods Receipt PO.
    But when the doctype is set to service, I got errors.
    I use for-loop to copy two items, Description and LineTotal, into the matrix of Goods Receipt PO form, but both failed.
    any suggestion?
    Edited by: Chao-Yi Wu on Aug 25, 2009 5:50 AM

    Hi  Chao-Yi Wu ,
    SBO_Application.ActivateMenuItem("2306")
    Dim oFormGR As SAPbouiCOM.Form = SBO_Application.Forms.ActiveForm
    Dim omtxIQC, omtxGR As SAPbouiCOM.Matrix
    Dim oedIQC, oedGR, oed As SAPbouiCOM.EditText
    Dim ocbIQC, ocbGR As SAPbouiCOM.ComboBox
    oFormGR.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE
    oedIQC = oFormIQC.Items.Item("13").Specific
    oedGR = oFormGR.Items.Item("4").Specific
    oedGR.Value = oedIQC.Value
    oedIQC = oFormIQC.Items.Item("21").Specific
    oedGR = oFormGR.Items.Item("24").Specific
    oedGR.Value = oedIQC.Value
    oedIQC = oFormIQC.Items.Item("edComments").Specific
    oedGR = oFormGR.Items.Item("16").Specific
    oed = oFormIQC.Items.Item("3").Specific
    oedGR.Value = oedIQC.Value + ", Goods Recript PO:" + oed.Value
    ocbIQC = oFormIQC.Items.Item("cbDocType").Specific
    ocbGR = oFormGR.Items.Item("3").Specific
    If ocbIQC.Selected.Value = "I" Then
         ocbGR.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
    Else
         ocbGR.Select(1, SAPbouiCOM.BoSearchKey.psk_Index)
    End If
    omtxIQC = oFormIQC.Items.Item("mtx_0").Specific
    For i As Integer = 1 To omtxIQC.RowCount
    omtxGR = oFormGR.Items.Item("38").Specific
           If ocbIQC.Selected.Value = "I" Then
                oedIQC = omtxIQC.Columns.Item("c_ItemCode").Cells.Item(i).Specific
                oedGR = omtxGR.Columns.Item("1").Cells.Item(i).Specific
                oedGR.String = oedIQC.String
                oedIQC = omtxIQC.Columns.Item("c_AQty").Cells.Item(i).Specific
                oedGR = omtxGR.Columns.Item("11").Cells.Item(i).Specific
                oedGR.String = oedIQC.String
                oedIQC = omtxIQC.Columns.Item("col_19").Cells.Item(i).Specific
                oedGR = omtxGR.Columns.Item("14").Cells.Item(i).Specific
                oedGR.String = oedIQC.String
       Else  
    omtxGR = oFormGR.Items.Item("39").Specific
               oedIQC = omtxIQC.Columns.Item("c_Descrp").Cells.Item(i).Specific
               oedGR = omtxGR.Columns.Item("1").Cells.Item(i).Specific
               oedGR.String = oedIQC.String
               oedIQC = omtxIQC.Columns.Item("col_16").Cells.Item(i).Specific
               oedGR = omtxGR.Columns.Item("12").Cells.Item(i).Specific
               oedGR.String = oedIQC.String
      End If
                Next
    for items the matrix is 38 and for service the matrix is 39
    Rgds
    Micheal

  • Goods receipt by using Vl31N for production order.

    Hi
    we can do Goods receipt by using inbound delivery VL31N, with confirmation control key in PO, for purchase orders.
    I want to do Goods receipt using Inbound delivery( VL31N), this is my requirement.
    how to do it.

    Hi
    I dont think you will be able to do Goods receipt against prodcution order using inbound delivery VL31N. Inbound deliveries are normally created for Purchase orders and then GR can be posted wrt to the inbound delivery.
    Prod order is normally within warehouse only so you can use MB31 and post GR directly against Prod order.
    If you can explain more about your scenario hope we may help
    Please let us know
    thanks

  • I am producing a 3d animationproduction. W want to work with artist all over the world. Is final cut server a good solution to use for such a production. I dont have a lot of computer nollege myself. Please can sombody advice me? tenaks

    I am a producer  and  starting with a 3d animationfilm. We want to work on it with 3d Artist from all over the world. Would final cut sever be a good program to use? I dony have many technical nolledge. Good sombody advice me? Thanks Will

    Only if all your artists have access to your local network, or an FTP server that FCSvr also has access to.

  • Whats a good mac to use for a home flight simulator with flight controls and foot pedals?

    whats a good mac to use for a home flight simulator with flight controls and foot pedals?
    My old 6100 AV worked great on A10 ATTACK, back in 1993.
    whats a good set up now a days?
    I havent seen any MAC set ups as a lot of the after market accessories are on  Windows platform.
    Is there a way or should I get a dedicated simulator on PC?

    The fact that USB flight input devices appear to Windows only is not a limitation; for Mac most are programmed through the sim itself. I know X-Plane does that.
    I've simmed a lot and know that good sims need a lot of processor and video hardware horsepower, and you'll also need a lot of RAM. They also run up the internal temps. A Mac Pro has better cooling than an iMac. You can get a program like SMCFanControl to manually set up the fans speeds before starting the sim.
    I know of no sims today that will still run on a PowerPC Mac (2005 and earlier) so you need to look to an Intel Mac with top specs. If looking at iMacs, start by looking for the quad-core i7 processor. Those models usually came with an up-rated video card. Thing 12 to 16GB RAM.
    My 2010 iMac has the 2.93gHz i7 processor, video hardware (ATI 5750) with 1TB VRAM, and 12 GB of RAM. It runs the x-Plane 10 demo fine but I've not bought the full version because v10 seems to make foot pedals darned near mandatory, and I don't want $100 worth of pedals under my regular work desk at the moment.

  • What's a good program to use to make flyers and handouts with?

    What's a good program to use to make flyers and handouts with? I'm not a wiz with computers so nothing too sophisticated is needed. Thanks!

    Pages would be fine but there are hundreds, I'd recommend using the Mac App Store.

  • What's a good speaker to use in an iOS Garageband Jam session ?

    What's a good speaker to use in an iOS Garageband Jam session ?
    Really I want to connect a few iOs devices together to create a loud sound...
    Any thoughts....

    Snapping with the iPhone is great when you out and want to catch something, but the care needed to capture a sheet of music requires focus, lack of keystoning (that's the big one - you're really going to have that lens absolutely perpendicular to the centre point of the sheet, and ignore any distortion towards the edges?).
    Sorry - if you want to reproduce music at a decent level, it has to be a scanner.

  • Looking for good easy to use inexpensive tuner

    Hi,
    I am looking for a good, easy to use, inexpensive tuner. Not one you use in a rack or on a pedal, but one you use on the computer. I looked and there are a ton out there so I figured I would look for recommendations here.
    I do not like the way GBs works. It fluctuates too much as the note decays and drives me nuts. I want a simple one, that works great. (If it has a feature that helps in tuning a 12 string, than thats a plus, but not a deal breaker). Simple and accurate is most important.
    Lastly I noticed some they sell are AU and some are stand alone. Is one better than the other?
    Thanks,
    Paul

    Strangedogs,
    Thanks for the link but if you read the review of it on the site, it is terrible. The users on VT hated it. It got 1 star out of 5. I was looking for a recommendation of one that someone has actually "used" themselves and likes it from experience using it.
    There was a link that someone posted there for a free tuner from emagic that they said is great, but all the links I found with google run to a dead end unfortunately.
    Paul
    BTW: boy do those 12 strings take forever to tune. I was jamming with a friend over new years weekend and it took him forever to tune up, (and he has an excellent ear).

  • Is Windows A Good Program To Use On Mac?

    I have a macbook and i would like to know, is it a good program to use on a macbook or any mac?

    Windows is not a program. It's an operating system that you run programs on. Whether or not you install Windows on you Mac is up to you. What is making you think you should install it? Do you have Windows only programs you need to run?

  • Is MacKeeper a good system to use?

    Is the Mac Keeper a good system to use? I have had Panda in the past.
    Does the new Safari browser provide adequate protection against viruses and malware?

    I totally concur with Niel.
    MacKeeper is crapware. It promises the world and delivers nothing. The little it can do, can be done for free with OS X.
    It is to be avoided at all costs.
    Allan

  • Wrong Unit Price in a Good Issue Document using DI

    Hi,
    in my addon I want to create a new Goods Receipt document, using DI.
    In the Lines, I set the ItemCode, I set the Quantity, and I set the Price, then I add the document, but when I go to Sap, in the Goods Receipt created, the Unit Price is wrong. I've try to set Quantity and LineTotal, Quantity and Price, Quantity Price and LineTotal but all the combinations is not correct, and the Unit Price is not equals to the price that I have set.
    I have try to change the Price List, but nothing is happened.
    This is my simple code:
    Dim entrataMerce As SAPbobsCOM.Documents = myDB.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry)
    entrataMerce.CardCode = cardCode
    entrataMerce.Series = series
    entrataMerce.Lines.ItemCode = itemCode
    entrataMerce.Lines.Quantity = 1
    entrataMerce.Lines.Price = 100
    entrataMerce.Lines.WarehouseCode = whsCode
    entrataMerce.Add()
    Where is the error?
    Thanks
    Marco

    Instead of Price, try using UnitPrice? This is a confusing area of the DI :/

  • Is it a good idea to use oracle database to process the geometry data?

    I am working on a map related project. Here are the stops I need to do.
    1. load geometry information from a table with spatial filter and other conditions (where clause)
    2. get the points from the geometry column (sdo_geometry)
    3. transform the coordinates
    4. encoding the coordinates
    5. output
    We have a third party applicaiton that can do both #2 and #3. However the process is slow. Some quick tests show that all the steps from #1 to #4 can be done within oracle and the speed is faster. My concern is if it is a good approach to use oracle, a database server, to do all the data processing that can be done and normally shoudl be done on a web server.
    Any adivce please?
    (BTW, we use oracle 10g on windows 2008R2 64bit, and we may upgrate to 11g in about a year.)

    Hi Simon,
    Thanks for your help.
    Yes all the steps can be done within the database side (Oracle). However I could do the same (extracting the coordinates from the sdo_geometry column, transforming the coordinates and encoding the coordinates) in .net code (web server side) by making use of the new verison of the odp.net. So I have to make a decision now to choose which approach to go, relying on Oracle server to do all the data processing or .net code. I am pretty sure Oracle can process a single request fairly quick, but if tens or even more concurrent requests for the process, I have concerns over the performance or reliability of the database server, especially the server is (a kind of ) beyond of our control (in control of the midware, IS and network team). Somebody said database is just a database and for data storing and retrieving, but may not for processing the data.
    Here is more information regarding what we are doing. We use Google Map API to disply parcels. Each time the map is loaded, panned, zoomed, or refreshed (and so on), we need to query the database with spatial filter and some other criteria. The result will be tens or up to handreds of parcels containing hundreds to thousands of coordinates that are extracted from the parcel table that has a sdo_geometry column. We are expecting tens to hundreds of these requests every minute.
    Now I am trying to chain every step together and do some tests using both appoachs in order to see which way is more effient and promising. I am guessing there won't be too much difference in terms of the performance for some simple testing unless I run some load testing, or if somebody like you guys can help me out.
    1. load geometry information from a table with spatial filter and other conditions (where clause)
    Regarding the issues you asked:
    ====================================
    I assume you mean something like: Yes
    CREATE TABLE load_table AS SELECT ID, GEOM FROM base_table where SDO_INSIDE(....) = 'TRUE';
    2. get the points from the geometry column (sdo_geometry)
    I assume you mean something like: Yes
    SELECT ID, v.x, v.y FROM load_table l, TABLE(sdo_util.getVertices(l.geom)) t;
    (See last comment about data.)
    The problem is that we need a lot more information on what it is that you want to do in steps 3 - 5.
    3. Transform the coordinates.
    What sort of transformation? Rotation, Shift, Scale, Coordinate rounding? Transform from UTM to LatLng
    4. Encoding the coordinates
    What do you mean by this? Write them out as WKT/KML/GML? Google map encoded polylines
    5. Output
    Again, output to what, where? A new table? A shapefile? A text file? JSONP formatted data
    Also, if you can provide a single sdo_geometry object + data and some example SQL it would help as well.
    Here is an example where I take a geometry, rotate it (cf 3. Transform), extract vertices (2. get points), encode it (4. Encoding), and then output to screen (5. Output).
    WITH myGeom As (
    SELECT 1 as id,
    MDSYS.SDO_GEOMETRY(2006, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1,5,2,1), MDSYS.SDO_ORDINATE_ARRAY(355600.52, 5407396.19, 361365.32, 5408106.36, 356488.27, 5409242.37, 357437.46, 5406457.67)) as geom
    FROM DUAL
    SELECT g.id || ',' || t.x || ',' || t.y as csv
    FROM myGeom g,
    TABLE (sdo_util.getVertices(
    GEOM.Rotate(p_geometry => g.geom,
    p_tolerance => 0.005,
    p_rotatePt => MDSYS.SDO_Point_Type(357437.46,5406457.67,NULL),
    p_rotation => 45 ))) t;
    -- Results
    CSV
    1,355474.91,5405822.39
    1,359049.08,5410400.89
    1,354797.2,5407755.57
    1,357437.46,5406457.67
    Now show us what it is you want to do!!
    Edited by: James Dong on May 31, 2012 11:41 AM

  • Is that a good practice to use syncronize methods for application scope cls

    Is that a good practice to use synchronize method in a application scope class, so I have a doubt, there a is class A, it has application scope and it contains a synchronized method add, so because of some network traffic or any unexpected exception client1 got stuck in the method, will that add method available for any other client...?
    Edited by: navaneeth.j on Dec 17, 2009 4:02 AM
    Edited by: navaneeth.j on Dec 17, 2009 4:04 AM

    If it needs synchronization, then it probably doesn't belong in the application scope. Either keep it as is, or reconsider the scope, or make it static.

  • Is it a good idea to use ABAP objects for reports?

    Hello Experts,
    Is it a good idea to use ABAP objects instead of the traditional ABAP for coding reports?

    Hi,
    Go throught Document it will Give you eight Reasons why OOABAP Should be used.
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/37c5db90-0201-0010-3a9b-d0a5288f3c15
    Must go through
    Regards,
    Gurpreet

Maybe you are looking for