Which is better OO design

Hi,
I have a class, lets call it MyClass.
public class MyClass {
  private String my_data;
  public MyClass(String s) {
    my_data = s;
  public String toString() {
    return my_data;
}Now, I have a different class that has a member variable called my_class of type MyClass. This other class implements Cloneable. So I write it like this:
  public MySecondClass clone() {
    return new MySecondClass(new MyClass(my_class.toString()));
  }It seems to me there is one other option, and that would be to have MyClass have a constructor that accepts its own type. Then MySecondClass.clone() would look like this:
  public MySecondClass clone() {
    return new MySecondClass(new MyClass(my_class));
  }Is one approach more preferable to the other? I don't want to look like an idiot and pick a bad design method.
Thanks.

The problem with Cloneable, as I understand it, is that there's no ironclad guarantee that the super
class has implemented Cloneable.Yes there is; ad ultimo there's the protected clone() method in the Object class. But there's
some fuzzy voodoo going on in that method, i.e. it checks whether or not the originating class (indirectly)
implemented the Cloneable interface. If not it starts whining, if so, it copies the entire originating
object by shallow copying all its members.
The nasty thing about cloning is that there is no guarantee that an appropriate clone() method
is available even if the class implements the Cloneable interface. It's all up to the responsibility
and discipline of the programmer.
The advantage of cloning is that one doesn't need to know the class an object belongs to, the
disadvantage is that clumsy implementation.
kind regards,
Jos

Similar Messages

  • I have a Question which is better to design a flyer for a furniutre store

    i can work with Photoshop which i know best, or Illustrator or indesign i need help please !

    I would use Illustrator for the document setup.  Plenty of fire power using typography tools, color, etc.  Believe it or not, I still start with a sketch or a rough pencil comp and show those if necessary.  Once the layout has been approved, then I can move on to preparing image files ( Photoshop ) at 100% final size for "Placement" into either Illustrator or InDesign.  I like Illustrator because it is faster ( for me ) and I can create a final PDF on the fly.  I would avoid doing any type of print work all in Photoshop.  File size and manageability quickly become issues.  How many images are you planning to use in the flyer?  Have you decided on a print vendor yet?  If so, discuss the project with them and get their file requirement checklist.
    And, take a look into Adobe's "Print Publishing Guide" for more info.  A very helpful resource.
    Message was edited by: jdanek

  • Which is better for gamming, Macbook Pro 13'' or Macbook Pro 13'' Retina?

    Which is better for gamming, Macbook Pro 13'' or Macbook Pro 13'' Retina?

    LowLuster wrote:
    You are certainly welcome to your opinion. I'll stick to my reply.
    In view of the fact that there are numerous applications that run properly while creating a lot of internal heat in a MBP indicates that it does not follow that heat is an inhibiting factor (within designed parameters).  Thus my comment is certainly not opion, rather fact.  You certainly are entitled to your reply but a third party reader should be be apprised of what the facts are. 
    Ciao.

  • Which is better - Mac book pro or air book ?

    Which is better a Mac book pro or an air book.  What is the pros and cons in using ?? 

    It depends on your preference and how you will use it. Example, if you're a designer, engineer, doing a lot of video editing, sound editing, then you'll appreciate the horsepower the Pro which means "Professional" can offer you. If you're a student, or someone who'll be using primarily for document making or presentation, then the Air would fit you, plus a bonus with the name Air which means "ultra light". The big difference though is the processing speed of the two laptops. The Pro uses full processor speed, while the Air for thermal concerns uses a slightly slower processor. 
    Good Luck picking the one which will suit you

  • Subquery vs UNION, which is better for performance?

    I want to know which in better for performance using a subquery method or a UNION?
    Any information would be helpful and appreciated!

    Hi,
    It depends on the SQL statments and each case is different from an other one. Take a look at the oracle doc: "Designing and Tuning for Performance".
    Regards,
    CB

  • Which is better to use: BEx query or Web Application as an iView in portal?

    Hi gurus!
    Are there any experienced opinions, which is better - publish a BEx query in portal or publish a BEx Web Application in portal? Is it easier to alter the layout attributes etc. if I create a BEx Web Application first before publishing?
    What is the way of fixing for example filter item height if I publish BEx query in portal - is there a Web Application that it uses anyhow which I can fix? Or can I use in that case iView -properties in portal?
    Thankful for advice
    Sari

    ok, means i can use jsp:useBean tag for all my
    classes that are not actually bean. so it will be
    instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
    >
    but when should i use import statement in my jsp and
    it happen at translation time so will it create any
    type of burden for my code if i import multiple
    classes.For non-java beans, you need to import the classes, period.
    It's not a burden, it's a necessity.

  • Which is better for performance Azure SQL Database or SQL Server in Azure VM?

    Hi,
    We are building an ASP.NET app that will be running on Microsoft Cloud which I think is the new name for Windows Azure. We're expecting this app to have many simultaneous users and want to make sure that we provide excellent performance to end users.
    Here are our main concerns/desires:
    Performance is paramount. Fast response times are very very important
    We want to have as little to do with platform maintenance as possible e.g. managing OS or SQL Server updates, etc.
    We are trying to use "out-of-the-box" standard features.
    With that said, which option would give us the best possible database performance: a SQL Server instance running in a VM on Azure or SQL Server Database as a fully managed service?
    Thanks, Sam

    hello,
    SQL Database using shared resources on the Microsft data centre. Microsoft balance the resource usage of SQL Database so that no one application continuously dominates any resource.You can try the 
    Premium Preview
    for Windows Azure SQL Database which offers better performance by guaranteeing a fixed amount of dedicated resources for a database.
    If you using SQL Server instance running in a VM, you control the operating system and database configuration. And the
    performance of the database depends on many factors such as the size of a virtual machine, and the configuration of the data disks.
    Reference:
    Choosing between SQL Server in Windows Azure VM & Windows Azure SQL Database
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here. 
    Fanny Liu
    TechNet Community Support

  • Which is better??????

    which is better?Dam really confused which speaker to buy??
    i currently have a creative m2600.but am not getting enough performance or that feel while watching movies like avatar,step up 3 etc......so am planning to buy a 5.1.......not planning but i have decided to buy a 5.1....so..
    which is better? the 6160 or 6060 or 6100.
    which of these will provide me relly great exprience while playing games and most importantly while whatching hd movies and while listening to music.......
    and other than this what i have to ask is...what is this "db" in speakers. i mean while looking at a speaker specs we can see it..like 65db,85db,75db..etc........
    and when i compared specs of the three speakers i mentioned above i saw that the 6160 has low "db"........why is that?

    The specs is just a guide, you won't be able to tell the slight difference in db using just your ears. Besides, it is just a comparison between the level of a music to the level of background noise, it does not necessary mean which speaker sounds better. If possible, please make a trip to your local electronics store and try out the speakers system yourself.

  • Which is better, Photoshop or Corel?

    Which is better, Photoshop or Corel? I am finding the best one to use for my website [link removed]. Let me know your opinion. Tks all.

    Thank you! I am trying to find the best one for the site [Link removed].
    I used to use Corel before, but now, I am trying to use Photoshop.
    Tk you anyway
    [Removed link]
    Message was edited by: sinious

  • Which is better software for brochures and PDF forms ? Photoshop or InDesign ?

    Which is better software for brochures and PDF forms ? Photoshop or InDesign ? and why ?

    If you are going to be making a lot of brochures, with photos, you probably want both. Photoshop to edit the photos, and InDesign to assemble and layout images with text.

  • Which is better an android or apple

    Which is better getting an android smart phone or an Apple I Phone?

    As the poster Horses 547 said its a matter of personal preference. However I own and use both. Printing via air print is smooth and easy on an iphone. Printing on a android phone is iffy and tedious and you will have to find an app to print since there is no native app to do so. I purchased http://www.printhand.com which costs around $12 from the app store. but it is in my opinion the best printing app out there for android. I use it on my android tablet as well and its great. This company is the maker of the print app on iphones.
    The iphone is a little harder to put your own ringtone on the device. However very easy from the Itunes you put on your computer and hook into.
    Another thing an iphone does is if you use their cloud service or pay for a song it is available on all your ios devices. Iphone, ipad, or ipod or up to five computers registered through itunes on those computers.
    Google play music also can sync with all your android devices.
    Iphone don't have external Micro SD card slots, so the storage on the phone is all you have.
    Iphones use imessage which does not count against your text allotment  to another iphone or ipad user. it send regular text to non iphone users.
    Another thing is Face Time but I found a better program called oovoo at http://www.oovoo.com or in the Google Play Store for free.
    Iphones are paper thin but I have an android that has a larger view area and is also paper thin and light. Depending on the android phone it may have a removable battery, whereas iphones are sealed as are some new androids. I have found the sound for music better on my iphone, and videos are crystal clear. Again on some better androids the music and video is comparable .
    There is really not many differences but it up to the user.
    One last good thing is iphones are updated via Apple, no long waits for OS updates like is done with Android devices, and android devices on Verizon.

  • Which is better for doing animation? Flash 4, 5, MX, CS, or others?

    Which is better for doing animation? Flash 4, 5, MX, CS, or
    others?
    I am used to using brush function more conveniently in Flash
    4 than the other versions I ve tried. However, Flash 4 doesn't have
    pen tool.
    Free News Reader
    http://put.hk
    http://put.hk/reader/forums.macromedia.com/macromedia.flash.html

    1Evan2Wing3 wrote:
    > Which is better for doing animation? Flash 4, 5, MX, CS,
    or others?
    >
    > I am used to using brush function more conveniently in
    Flash 4 than the other versions I ve tried. However, Flash 4
    doesn't have pen tool.
    all pretty identical tho I would go with cs, just because I
    like the GUI much
    more than other versions...
    Best Regards
    Urami
    "Never play Leap-Frog with a Unicorn."
    <urami>
    If you want to mail me - DO NOT LAUGH AT MY ADDRESS
    </urami>

  • Which is better for bulk message scenario in sap xi RFC or Proxy

    which is better for bulk message scenario in ( RFC or Proxy ) ?
    Edited by: prabhatxi on Aug 6, 2010 4:44 PM

    Proxy will alwaays be better option in this case, as it is adapter less framework, and communication happens directly with XI central integration engine. So it is always fast communication and gives good performance.
    But still you should consider other factors, you may consider using RFC as well, as sometime we go for RFC/IDOC as this are the standard interfaces already available rather than creating structure...
    May be you can share more info on what type/volume data are you planning to send via XI?
    Hope this cleart your doubt..
    Divyesh

  • Which is better - Add a dimension or create more members in an existing

    Which is better - Add a dimension or create more members in an existing dimension?
    We are trying to figure out which can give us better performance in terms of calculations and retrieving reports - to add another dimension (entity/country) or add about 500-800 more members in an existing location/division dimension?
    Thank you!

    If you have BSO cube i would recommend to add in the same dimension where as ASO you can add members in a new dimension. Adding a new dimension is like creating a new cube you have to change each and every single calc scripts,report scripts,FR reports,Webforms and your rule files .... all the dependencies has to be changed manually . I think 500 members in the exsting BSO dimension will not impact the calc or retrieval times that much .

  • Which is better for servers, Apache or Tomcat?

    Which is better for servers, Apache or Tomcat?

    For some reason that link I gave you isn't working right now, but it was today, weird. I would get Tomcat simple because sun uses it in its examples and recommends it. Here's sun's link then, it's probably more useful anyway. http://java.sun.com/products/jsp/

Maybe you are looking for

  • Creative ZEN V: Display; FAQ & Knowledgebase unhelp

    Creative ZEN V, GB When initially placed on the charger, the device seemed still to function. When removed from the charger 4-5 hours later, the ZEN no longer functioned properly. Though the blue power lights would activate, the display is entirely b

  • I can no longer customize the TOOLBAR in PAGES

    It won't allow me to drag and drop the way that it used to. I have no idea why - maybe I changed something without realizing...?

  • Function of this report RDDEXECL

    Hi, I would like to know the function of this report RDDEXECL. Kindly give a detailed explanation about this report?In addition I woould like also to know when to use this report? Regards,

  • PSE 8 (OSX) Drop out part of photo to reveal another?

    I am guessing it's possible to crop inside one photo, drop that part out, and thereby reveal a photo underneath. But I can't find any hook in Help (or in The Missing Manual) to let me start researching it. Is it possible? Can you give me an idea how

  • Refrence forms in application

    Hi All, Is there any way to know a particular Refrence form is subclasses in these many forms ? we are having some refrence forms, which are subclassed in main application forms. These refrence forms are used to keep common functionality in one form