Is this bad practice?

Consider the follwing two classes:
public class Widget
public class CustomWidget extends Widget
}Now consider another class that has a Widget class member:
public class OrdinaryClass
  private Widget w = new Widget();
  public Widget getTheWidget()
    return w;
}Now suppose I were to subclass OrdinaryClass as follows:
public class SpecialClass extends OrdinaryClass
  private CustomWidget cw = new CustomWidget();
  public CustomWidget getTheWidget()  // violate LSP?
    return cw;
}My questions are:
1) does SpecialClass violate Liskov's Principle in that the getWidget return type has changed?
2) if it's not in violation, is it bad practice anyway? Or is this some polymorphic trick that is not only acceptable, but very useful (and encouraged)?
Please advise.

A custom model was subclassd from AbstractListModel.
One of the getter methods from ALM has a return of
f type Object. The custom model used the same
getter, but returned the toString() of the Object (a
property) instead of the Object in its entirety.Given this specific class hierarchy, you're into territory for design lawyers. A list mode maintains data that's used by a JList[i/]. The contract, as a result, is fairly open, and you could define the model as maintaining string representations for an object. The purists would respond with "no, the view should decide the representation," and I'd probably agree with them.
By comparison, the contract for a [i]java.util.List is much more explicit: you put objects into the list, and you get the same objects out. If your colleague was creating a List implementation that returned toString() of an object rather than the object itself, then your argument would have much more force.
It seems as if changing the return type of a method
in a subclass seems wrong, even if the new return
type is a sub of the original return type.
I have nothing against returning the subclass, mind
you. Just keep the contract (i.e, the return type)
the same.However, the "contract" is not defined just by method signature. If that were the case, then this would be a perfectly valid implementation of List.get():
public Object get(index i)
    return new Integer(i);
}Instead, the "contract" is defined by the class as a whole, and furthermore is defined by your application for each instance of a class that it creates (eg, "this List is used to pass strings between these two methods").

Similar Messages

  • Workaround good/bad practice or does it not matter...??

    Hi,
    I have a project that requires other shared actions to hide./show something and was wanting a quick workaround for Hide 1 show 9 so I did as follows..(bear in mind I am using CP7 not 8)
    I copied my hide1 show 20 slide from another project, which retains the connection between buttons and images etc, but as this was too many for my other project, I just set things on the copied slide not to  displlay in output etc adn then renamed the ones I wan to refer to in the new project adn it all works great, however, if wer are doing this is this bad practice as any other CP editor further down the track, needs to edit the project, might think that this is a mess and mish mash with ttoo many objects (although hidden) on the slide and maybe make it more difficult for them.
    My initial thinking on that is while it may look a bit of a mess, My approach to any exising project is to deconstruct it to see exactly what is going on, but some otheres might just look at it as a real pain. (I did it this way as I could not edit a shared action in CP7)
    So, I was just wantig to pose this question to the community and get any feedback on your thoughts about this approach...? (I hope I have explained this correctly and is understandable etc)
    Cheers
    Rossco

    Hi Lilybiri,
    Sorry for the delay in responding.
    I would be interested in your workflow for editing shared actions.
    Hopefully this will be clearer for my explanation of how I initially thought of for editing my shared action...please let me know if this is still not clear.
    I had a Show 1 Hide 20 shared action, using smartshapes as buttons and aside from checkmarks (Ticks) and other images etc.
    I needed to create another similar advanced/shared action, but did not have the time to do so, I needed to just change the existing shared action.
    To do this, I copied the shared action to another project and tried to think of a way I can edit this just by changing the items on the slide. So I tested it out, by selecting a  number of images/buttons and making the ones I did not need, to not be buttons and to not show in output, then just renaming the ones I wanted to show etc...
    And it worked well, so I was happy with that outcome. It may have taken me a while to figure it out initially, but now I know it can be done :-)
    The only negative that some of my colleagues have said, are as follows,with my response back to them.
    Issue: The slide will be a mess as all those items/images are still on it. My response:You can hide the items not used so the slide will not look messy to another CP editor.
    Issue: the images etc will make the file too big and unwieldy My Response: remove the images not needed and the file size will not be a problem.
    Issue: File will be messy for another CP editor to change and take un-necessary time. My Response: Anyone who is a CP user, will/should know how to deconstruct and edit an existing file.
    I hope that makes it clearer :-)
    Cheers
    Rossco

  • Bad practice to put everything in single try block?

    I have a small application that reads in from a couple of files. It just has a main method, and a single sub-class. Everything in the main is within a single try/catch block. Is this bad practice? (Been a while since I programmed java).
    Thanks

    >
    Welcome to the Sun forums.
    I have a small application that reads in from a couple of files. It just has a main method, and a single sub-class. Everything in the main is within a single try/catch block. Is this bad practice?It depends on the detail of what you are doing. If you find you match any of [these antipatterns|http://today.java.net/lpt/a/280] then worry a bit more.
    Edited by: sabre150 on Jul 17, 2009 12:31 PM

  • Hi, I'm designing my 1st website and I started it in  photoshop cs5.5. I know that it's bad practice

    Hi, I'm designing my 1st website and I started it in  photoshop cs5.5. I know that it's bad practice to build with images, I learned this too late. I imported my site into Dreamweaver cs5.5 and uploaded it to my server. The problem I'm having is that I want to apply a jquery drop down menu bar but whenever I try, I get white gaps within my page. How do I convert the coding into a functioning site?*Help Please*  The URL to my site is: http://www.coriemoment.com and this is my coding:
    <html xmlns="http://www.coriemoment.com"
    <head>
    <title>The Official Corie Moment Home</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
        <div id="=container"
    <body bgcolor="#FFFFFF" leftmargin="auto" topmargin="auto" marginwidth="auto" marginheight="auto" margin:0;>
    <!-- Save for Web Slices (home.psd) -->
    <table id="Table_01" width="1281" height="768" border="0" cellpadding="0" cellspacing="0">
              <tr>
                        <td colspan="6">
                                  <img src="images/index_01.png" width="1280" height="220" alt=""></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="220" alt=""></td>
              </tr>
              <tr>
                        <td rowspan="4">
                                  <img src="images/index_02.png" alt="" width="414" height="548"></td>
                        <td rowspan="3">
                                  <object width="564" height="423"><param name="movie" value="http://www.youtube.com/v/XbuQiJ6Sv_M?hl=en_US&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/XbuQiJ6Sv_M?hl=en_US&version=3" type="application/x-shockwave-flash" width="564" height="423" allowscriptaccess="always" allowfullscreen="true"></embed></object></td>
                        <td colspan="3">
                                  <img src="images/index_04.png" width="255" height="89" alt=""></td>
                        <td rowspan="4">
                                  <img src="images/index_05.png" width="46" height="548" alt=""></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="89" alt=""></td>
              </tr>
              <tr>
                        <td rowspan="2">
                                  <img src="images/video_03-07.png" width="1" height="336" alt=""></td>
                        <td rowspan="3">
                                  <img src="images/index_07.png" width="34" height="459" alt=""></td>
                        <td>
                                  <script src="http://widgets.twimg.com/j/2/widget.js"></script>
    <script>
    new TWTR.Widget({
      version: 2,
      type: 'search',
      /*put your twitter id that people use to reply to you below. Mine is mhorning. If you only want to see the Tweets that you have Tweeted, then delete the part below that says- OR to:coriemoment */
      search: 'from:coriemoment OR to:coriemoment',
       /*this is the duration in terms of seconds*/
      interval: 30000,
       /*this is the title you want on your tweets*/
      title: 'Corie Tweets',
      subject: 'Send us your comments',
       /*setting width to 'auto' will adjust the width of your tweetbox to whatever is set on your div. You can change this to something like 500px if you want*/
      width: 'auto',
      height: 212,
      theme: {
        shell: {
                 /*this will change the background color of your tweetbox. It is currently yellow*/
                background: 'body p, body img, body embed, body object, body video{opacity:1 !important}',
          /*this will change the color of the text in your background*/
                color: 'fac935'
        tweets: {
                 /*this will change the background color behind your tweets. It is currently white*/
                background: 'body p, body img, body embed, body object, body video{opacity:0.2 !important}',
           /*this will change the color of the text in your tweets. It is currently black*/
                color: '#000000',
           /*this will change the color of anything that is hyperlinked in your tweet. It is currently blue*/
                links: '#1985b5'
      features: {
        scrollbar: false,
        loop: true,
        live: true,
        behavior: 'default'
    }).render().start();
    </script></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="302" alt=""></td>
              </tr>
              <tr>
                        <td rowspan="2">
                                  <img src="images/index_09.png" width="220" height="157" alt=""></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="34" alt=""></td>
              </tr>
              <tr>
                        <td colspan="2">
                                  <img src="images/index_10.png" width="566" height="123" alt=""></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="123" alt=""></td>
              </tr>
    </table>
    <!-- End Save for Web Slices -->
    </body>
    </html>

    mazz2000 wrote:
    The best way to do it is go back to PS and place the navigation area in the design, i would make it 100% of the width and then re-slice the design making sure one single slice is the whole of this navigation area.
    That would be the best way to do it while still using a table layout which in and of itself is not recommended, in large part  for this very reason.
    Every time you want to make a small change to the layout of your site, it will require re-slicing and re-generating code out of PS. You would be much better off taking the time to understand css layouts. Here is a good place to start to get the basics of css: http://www.w3schools.com/css

  • Is it ever bad practice to use threads?

    Hi there ppl,
    this may sound like a really silly question is it ever bad practice to use threads? I actually have never explicitly used threads and came across a simple swing application recently which used a thread in the code. Then I started to think that if ever a scenario came up where I was expected to use threads I'd have to learn something new that I should I have already known from birth, then run and hide behind the JAVA API (which is big, real big, BIGGER THAN OPRAH!!!).
    So for now I'll "synchronise my watch" (PUN INTENDED), and await the flood of replies.
    Thx already ;)

    Main Entry: 1pun
    Pronunciation: 'p&n
    Function: noun
    Etymology: perhaps from Italian puntiglio fine point,
    quibble -- more at PUNCTILIO
    : the usually humorous use of a word in such a
    way as to suggest two or more of its meanings or the
    meaning of another word similar in sound
    emphasis mine (synchronize watch vs. synchronize
    threads)...
    Ironic that it derives from "fine point, quibble."
    &para;

  • Multi-functional Servlet considered bad practice?

    Hi,
    is it considered bad practice using doGet() for fetching say a blog entry and using doPost() for saving new entries or comments?
    Such as:
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         blog.getPost(id);
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         Post post = new Post(title, msg, category, author);
         blog.save(post);
    }I like to think that this is the reasoning or at least part of the reason why doGet and doPost are separate methods.
    Thank you.
    Regards,
    Adam

    Asham wrote:
    Hi,
    is it considered bad practice using doGet() for fetching say a blog entry and using doPost() for saving new entries or comments?Depends on current environment and requirements. In a small hobby application you can do so. In real business I wouldn't do so, it might bite in the future if you plan to extend that servlet with more logic.
    I like to think that this is the reasoning or at least part of the reason why doGet and doPost are separate methods.No, it is not. The HTTP protocol specification (1) offers several request methods, GET, POST, HEAD, PUT, DELETE, etc. The HttpServlet API (2) offers overrideable methods for each of those request methods so that you can handle it using some Java logic. A "plain vanilla" request is always GET. A form submit can be either GET or POST -generally POST is preferred as it can transfer more data and does "hide" query parameters.
    (1) http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
    (2) http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServlet.html

  • Force quitting InDesign as a Matter of Routine. Bad Practice?

    I am trying to convince InDesign users here (CS4, CS5) that using Force Quit as a matter of routine for quitting out of InDesign at the end of the day is a bad practice. I think this started because when we were using K4 (enterprise InCopy/InDesign plug-ins), InDesign DID take a long time to quit because of communication to the K4 database and disconnecting.
    I need some good evidence to convince everyone to quit out of InDesign normally. And also other programs they use. My argument is that when InDesign quits, it updates its preferences and perhaps may even clean something up. Anyone know?

    I work on local files only, and I still have to either leave my desk for 10 minutes after I try to quit then shut down, or force quit and shut down. I do work on some large files though (50-100 meg catalogs) with lots of photos linked in. I guess it takes forever to clear all the cached memory or something. If I try to do a shutdown with InDesign open. I always get a time out error. Also when I go back to InDesign after working in Photoshop, FreeHand, Entourage or FireFox it takes a long time to redraw the InDesign screen and menus.
    I also have a couple of indexing scripts, but don't run them often. Don't see how that would affect anything.
    I read a post somewhere that you could change the "Live Screen Redraw" setting to help with the slowness, but I cannot find that setting in CS3. It may only be in later versions.
    Thanks,
    BJ
    iMac 2.1 GHz PowerPC G5
    Mac OS 10.4.11
    1 GB DDR2 SDRAM (that's wierd, I thought I had 2 GB)

  • Is it bad practice to capture an image that was deployed from mdt after adjustment?

    is it bad practice to capture an image that was deployed from mdt after adjustment?
    or there is no any consequences?
    &quot;When you hit a wrong note it's the next note that makes it good or bad&quot;. Miles Davis

    During years I never captured the image deployed from mdt.
    Today was a rush.
    The request:
    to install time consuming configuration application into the image.
    I restored acronis image that used during couple of weeks for captures after small changes.
    And decided to capture it again before the installation of local progam and final capture.
    It failed after multiple trials. I posted the error yesterday here:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/a702bf17-8375-4bc7-b458-8ce4894f99e9/error-2147467259-during-capture?forum=mdt
    As a last tip before suggesting to deploy existing image and sysprep it 20 times I deployed the image from MDT applied just Windows KBs and captured again with MDT it worked without any prob.
    So against my usual habit I gave a deployd image for installing the tricky software and then will capture it for future deployment for 20 "special" computers. Feel not so good. But like you told:
    "Will it hurt anything?  Probably not"     I took a chance. In the image no AV, just small things like 7Z and Adobe.
    Encourage me for this case :)
    Thanks.
    &quot;When you hit a wrong note it's the next note that makes it good or bad&quot;. Miles Davis

  • Catalogue of SQL and PL/SQL bad practices: Call for participation

    I started compiling a list of Oracle SQL and PL/SQL bad practices, with the intention of producing a comprehensive catalogue of common and recurring programming mistakes, that can be used as a check-list for code reviews or given to junior developers. I have identified about 30 bad practices so far. For each bad practice, I provided a list of symptoms in the code, an explanation why it causes problems and a list of preferred solutions.
    My goal with this list is primarily to start a discussion about similar recurring issues that other people have noticed. That discussion should lead to a more complete list which the community will then be able to use, hopefully, to learn something from the mistakes of others and to produce better code.
    I would really appreciate your feedback - if you are interested in discussing these practices we can either do it in this forum, or start a separate mailing list.
    You can download the first version of the catalogue in PDF form from http://gojko.net/effective-oracle
    gojko adzic
    http://gojko.net

    exception handler (already covered), the philosophy
    behind not using stored procedures, and having beenHi riedelme,
    I'm not advocating not using stored procedures, but I am advocating not using exclusively stored procedures. I've seen that approach often, typically with people coming from SQL server or Oracle forms backgrounds, I never could understand the reasons behind it. Even for a simple select or update, they would write a stored proc that wraps the call and then require the client to execute a stored proc.
    I think that views are much better for getting the data out of the database in general, and forcing people to use stored procedures with ref output cursors makes little sense. If the only possible interface is a stored proc, then one proc must be created for every required combination of data and every required filtering or grouping method, so there is much much more code in the database, and more code means harder maintenance.
    If client apps can get data out using views, then they can join them with other views, filter or group the data as they require, which means that there is a lot less code in the database to maintain.
    My other problem with stored-proc only approach is when people wrap simple insert/update/delete commands into a stored proc. Again, I'm not advocating using complex instead-of triggers to implement workflows and forcing people to use views, but I simply don't see any benefit of implementing a stored proc to do a simple update. I see a bad side of it because a stored proc needs to be implemented for every combination of columns that a client may need to update and every criteria that can be used for that. If a client is allowed to update a view, there is much less code in the database.
    Views are, in my experience, also a lot easier to maintain and optimise without downtime because they can be revalidated without causing any problems to currently connected clients, where revalidated stored procedure or package will throw an exception the first time a connected client that had called it before calls it again.
    If I'm missing something, please tell me. I'd really love to understand why someone would build a client API exclusively from stored procedures.
    So far, I've been given explanations that it is for security purposes, or for performance. I don't know of any security restriction that can be implemented on a stored procedure or package that cannot be implemented with a view, and if bound variables and statement caching is used, sql statements don't suffer from sql injection and support pre-compilation.
    Again, i'm not advocating throwing stored procs completely out, i'm against using them exclusively and throwing out any chance of SQL access.
    gojko adzic
    http://gojko.net

  • Bad practice to assume ordering of columns using *  ??

    I am using Pro*C -- embedded sql
    I have a table with 60 columns and it is partitioned by datetime. It is constantly getting new rows via an array insert, inserting 10 to 100 million rows a day depending on the installation.
    I am currently using select * for the querying.
    I am inserting an array:
    exec sql for :cnt insert into x values (...);
    Is it more efficient or bad practice to assume the ordering of columns. Is it better to list the columns explicitly in the select/insert?
    thanks, lisa

    Yes.
    Imagine if you have added a new column to the table and that column has a default value assigned for older applications (only newer applications will use this added column, old applications should still work), you do not have to re-visit the old application code to change all those insert statements. Only new applications will need to care about what value to put into this newly added column.
    This helps avoid unnecessary changes to existing applications if the new column(s) is added to support new applications only.

  • Is this bad: g.drawImage(img, 0, 0, null);

    Is this bad: g.drawImage(img, 0, 0, null);
    I don't know if I need an ImageObserver "reference"(?) in this method. I see know need for it.
    Thank you.
    Joshua

    The last parameter is the observer that will be
    notified when the image has been completely loaded -
    recall that loading of images is asynchronous and
    lazy. If the parameter is null no one is told when the
    data is complete and you might end up showing no image
    at all until the next update or repaint.
    That means that it is fine in an animation loop when
    you are drawing images whose data is immediately
    accessible.I had a feeling it would be okay since I had already loaded my images with MediaTracker. Thanks.

  • PCI-5114 clicks when the trigger is changed---is this bad?

    Hi everyone,
    I'm working with a PCI-5114, using several triggers in a LabVIEW program that loops every second.  In the program, I first trigger off of channel 0, then I reset the trigger to collect different information, this time triggering off of the trigger channel, and reading out channel 1.  This works, and I get the data that I want (hooray!), but every time the trigger changes (once per second), I hear a loud click from the PCI-5114.  Is this bad?  Will switching like this eventually harm my digitizer? 
    If it's not bad, I'm happy to endure the clicking.  If it is bad, then I need to figure out a new way to read out my card.  
    Thanks in advance!
    Solved!
    Go to Solution.

    Hello Karl,
    Some scope cards, such as the PCI-5114, have active switches in them.  The noise you are hearing is the switching anytime you change your analog trigger from one channel to another.  These switches will eventually go bad after extended usage, so I highly recommend that you stop switching the analog trigger back and forth each iteration of your loop.  Once the switch goes bad, your card will have to be sent in for repair.  Instead, you may want to look into using one of the PFI lines as a trigger instead.  
    Regards,

  • I forgot my ipad on charge after 100%,is this bad for ipad battery?

    I forgot my ipad on charge after 100%,is this bad for ipad battery?

    Once the battery was fully charged, the smart circuitry stops charging the battery.  Power is then used just for running the device, and the charging circuits will not cut back in until the battery has spontaneously drifted down by 5%-10% of a full charge (which should take days with a normal, healthy battery).
    You cannot over charge any Apple device.

  • Toshiba E55 exausts heat from rear, is this bad?

    The heat heats up the screen allot. Is this bad? Would a laptop cooler help?

    I see it's just odd the exaust lands on the screen. I've bought those little clear rubber riser pads you get at target or wallmart. I hope this allows it to "breath" more and keep the screen bottome center from getting hot. I actually preffer th exause to left not the rear. At least it wont touch anything.
    Also, when I remove the cover to change the ram(add) can you clean the fans out?

  • I can't open my gallery after i migrate the iphoto! How can i fix this bad problem?

    HI,
    I can't open my gallery after i migrate the iphoto! How can i fix this bad problem? Flz help me!!

    Try repair permissions with Disk Utility
    Regards
    TD

Maybe you are looking for

  • Ehternet... PC to mac mini

    I'd like to use my PC for streaming TV shows and feed it to the mini. Seems the most reliable and fastest performer is to run CAT 5 ethernet in-between both the PC and mini. Q: how does one accomplish this?

  • BAPI to create vendors

    Hi, This is the standard function module (Bapi_Vendor_Create) to create the vendors. DATA: verbuchter_lieferant LIKE lfa1-lifnr, msgv1 LIKE sy-msgv1. SET PARAMETER ID 'LIF' FIELD vendorno.* CALL TRANSACTION 'XK01'. Wurde der Verbucher aufgerufen? Par

  • How to get pending TRs for production ordr ?

    Hi, Is there any way to get pending TRs w.r.t., production order. Im actually looking for a t code or tables that could link these twos. It could be possible via. material doc. or TOs but not sure how. Please let me know if any idea in this. Rgds sud

  • Any one who is doing FICO Certification??

    Hello Everyone, If any one is preparing for below Certification, let me know. SAP Certified Application Associate - Financial Accounting with SAP ERP 6.0 EHP4 We can discuss queries related to that. Thanks, Pinky Moderator: Please, read and respect S

  • Saving/backing up Newsstand purchases

    Hi all, I've just had an email from the publisher saying that a weekly magazine I have subscribed to for almost a year is being discontinued and that, should I change devices or delete the app, I won't be able to access them again. My questions are: