Prototype Design Pattern in Java

Поделиться
HTML-код
  • Опубликовано: 22 ноя 2024

Комментарии • 117

  • @mishamovdivar
    @mishamovdivar 7 лет назад +142

    Demo for shallow copy is wrong.
    You are removing third item from bs BEFORE you clone it, so, whether it's deep or shallow copy, third element wont be copied into bs1.
    Instead you should remove third element from bs1 and print bs and observe that third element was also removed from bs (which demos that bs and bs1 are referring to same memory (shallow copy))

  • @Ranjith_P
    @Ranjith_P 6 лет назад +65

    I have been called a lot of things in my life , never been called a Alien ...

    • @mohan-ri6ze
      @mohan-ri6ze 3 года назад +3

      He thinks he have subscribers from other planets also

    • @vimalbhatt5359
      @vimalbhatt5359 2 года назад +1

      He is from Pluto that's why we are aliens to him

  • @paranjisridhar5529
    @paranjisridhar5529 6 лет назад +36

    There is a problem in your example. You are still doing shallow cloning of the books. By iterating thru the list of books and adding each book to the second book shop you are still adding references to the second book shop. You can see the effect by renaming one of the books in the first bookshop instead of removing it, the name will be changed in the second one too.
    Removing the book from the first bookshop removed it from the list(which is a different object in the two bookshops) but the book is still there because the second book shop refers to it in its list.

    • @maolyherrera4240
      @maolyherrera4240 5 лет назад +14

      That's correct. To make it deep; in BookShop's clone() method, under line 43: for(Book b: getBooks()) it should be added: Book newBook = new Book(); newBook.setBid=b.getId(); newBook.setBname=b.getName(); shop.getBooks().add(newBook);

    • @adityajagtap4349
      @adityajagtap4349 4 года назад +2

      @@maolyherrera4240 Better way is use clone() in Book

    • @it-family-
      @it-family- 4 года назад +1

      You are wrong! It is exactly a deep copy already. The idea is that the cloned object contained a List of objects in which we have first field int id (primitive - no reference) and second field String (an immutable type of object). So, no need for those object to make a copy, we could reSet them both in cloned object with no impact to origin object.

    • @abhishekkorlekar7966
      @abhishekkorlekar7966 3 года назад +2

      Yup are you right!!
      I renamed in the first object by: obj1.getBooks().get(0).name = "Some Name";
      This changed the name in another bookShop object as well

    • @little-by-little-one-trave1770
      @little-by-little-one-trave1770 2 года назад

      @@maolyherrera4240 Minor improvement to your code we can implement clone(deep) in Book and inside for loop we can do --> Book newBook = b.clone();

  • @jasper5016
    @jasper5016 Год назад +3

    I really love your explanations. Why didn't you cover all design patterns?

  • @myangelsworld6566
    @myangelsworld6566 9 месяцев назад

    awesome explanation !!!! The only thing is playback speed is a little faster.

  • @naveengamini3445
    @naveengamini3445 5 лет назад +3

    You are aweome Navin.. I like your live programing skills with fastness and help us to learn the concept and also live coding, test the code and debug.. Awesome videos..Thanks

  • @amitkhandey3582
    @amitkhandey3582 2 года назад

    Hi Navin, I you have excellent ability to explain things in very simple way.

  • @SunilKumar-pd9eh
    @SunilKumar-pd9eh 7 лет назад +5

    when you were explaining about deep copy, I felt there was no use of overriding clone method, you can do the same with any normal method as you were not leveraging the advantage of overriding the clone method. You can simply say copy method and do the same stuff. It doesn't need to be clone really. Please correct me if I understood wrong.

  • @tusharkale9578
    @tusharkale9578 2 года назад +1

    at 13.05 .. you are first removing object book-3 and then cloning so its affecting both BookShops.. not because of shallow copy

  • @kathiravanjagadeesan
    @kathiravanjagadeesan 5 лет назад

    Awesome work by another indian .

  • @sakshisharma7097
    @sakshisharma7097 7 лет назад +2

    i love the way you make everything simple and cooler :)

  • @liponrr9737
    @liponrr9737 7 лет назад +3

    You are a awesome teacher

  • @hardstuck170
    @hardstuck170 7 лет назад +1

    questions:
    1- why no public/private indentifier before the List field, what's the meaning of no identifier?
    2- why do you fetch the list with the getter. I think you can do it directly since you are in the same class

    • @KushalMaharana
      @KushalMaharana 7 лет назад +1

      1. public protected private default are not identifiers they are access modifiers. When you don't specify a access modifier compiler consider as a default modifier that means that list can be access in the same package only.
      2. Every object of type BookShop contains that list so it's not used for internal operations of BookShop class. Thats why sir have set a getter method to call it on object.
      Please correct me if I'm wrong!

  • @vinaysingh2971
    @vinaysingh2971 3 года назад

    Very well thoughtfully explained

  • @buildleadinnovate24
    @buildleadinnovate24 7 лет назад

    your way of teaching is improving day by day...I am watching your videos when u have other channel name naveen reddy

  • @cristianflorentintarta885
    @cristianflorentintarta885 2 года назад

    Navin's videos should not have a dislike button / it's useless :)

  • @vishaldindalkop294
    @vishaldindalkop294 2 месяца назад

    Thank you for the video

  • @rithikraj4316
    @rithikraj4316 3 месяца назад +1

    So why don't we use copyConstructor ?? which sole purpose is to give me value of other object ? or copy constructor comes under prototype design pattern ?

  • @JafarAliyev
    @JafarAliyev Год назад

    Mistake in 13:36 time. In order to demonstrate shallow cloning you had to remove an element after calling clone() method. Not before

  • @noahvo6673
    @noahvo6673 3 года назад +1

    Im not sure the demo is correct. does this mean:
    one method they use the same memory for the database and have 2 pointer point to that memory. This cause change one object will lead to the other change too
    and the other, they use different memory so they are independent to each other

  • @swatiyadav9842
    @swatiyadav9842 4 года назад

    Nice explaination.

  • @buzzbummer2111
    @buzzbummer2111 5 лет назад

    Awesome tutorial video, Thanks Sir

  • @mermerjamal6662
    @mermerjamal6662 Год назад

    thanks for you great vedio

  • @asheeshpratapsingh4948
    @asheeshpratapsingh4948 6 лет назад

    is Use of prototype design pattern with factory Pattern good approach ?

  • @ranilutube
    @ranilutube 6 лет назад

    This is very useful..

  • @gouraharidas
    @gouraharidas Год назад

    Are you not doing the swallow copy of the objects in the loop? You should have written list.add(b.clone())

  • @Xenon77x
    @Xenon77x 4 года назад +2

    his head shines brighter than my life

  • @vnm_8945
    @vnm_8945 6 лет назад

    can you make more of this, really appreciating your videos!

  • @vladimirjevremov5581
    @vladimirjevremov5581 7 лет назад +2

    Great work, keep it up !!

  • @abhilash1755
    @abhilash1755 Год назад

    If we are creating another object inside clone method is it really prototyping ?

  • @aashishgoyal1436
    @aashishgoyal1436 6 лет назад

    thanks a lot naveen sir

  • @rakshamalviya3450
    @rakshamalviya3450 5 лет назад +1

    At the time of shallow cloning u r removing element and then cloning so any how third element will not reflect in the copy object whether it is shallow or deep cloning. You need to update ur video

  • @PostMapping
    @PostMapping 3 года назад

    Thanks!

  • @ujjawalgupta5408
    @ujjawalgupta5408 4 года назад +1

    While doing Shallow copy, I changed the shop name in bs1 and after changing it I printed bs but still I got shop name as 'Novelty'. So, as you said it refers to the Object then shop name should also change. Can you please explain what happend here?

  • @SurajGaikwad-j5z
    @SurajGaikwad-j5z Год назад

    some articles on google says there are 3 components in prototype design pattern, 1.prototype, 2,ConcreteProtoype and 3.Client in this video who is which one.

  • @niteshagarwal4934
    @niteshagarwal4934 5 лет назад

    why we are using clone method.?we can create any custom method and do the same task.How does it is different from the clone?

  • @arindamsarkar3383
    @arindamsarkar3383 2 года назад

    Inside your overridden clone() method you are using "BookShop shop=new BookShop()". Is it not creating a new object through new keywords instead of cloning?

  • @yatri6329
    @yatri6329 3 года назад

    What about immutable obj do we need copies of that. If not why?

  • @sanjeen2503
    @sanjeen2503 2 года назад

    Hey Naveen, I think it would be better if you prepared the content beforehand, rather than just the outline. It is confusing when you move logging statements around on the fly.

  • @rajsaraogi
    @rajsaraogi 2 года назад

    How implementation of Cloneable given permission to class to add clone method, can you clarify more on this.

  • @vigneshv1517
    @vigneshv1517 7 лет назад +4

    prototype design pattern another good example is... one friend downloads a movie from internet and we people get that using pendrive. am i correct sir??

  • @prathammodii
    @prathammodii Год назад

    navin reddy bhagwan. jay ho kaka

  • @srinivasjava1932
    @srinivasjava1932 4 года назад

    Thank you Sir

  • @kumodsharma8141
    @kumodsharma8141 5 лет назад

    Nice explained

    • @kbhardwaj1989
      @kbhardwaj1989 5 лет назад

      Mr KMD, you watched this video very late. Naveen sir has shared this video 1 year back. Do follow his vidoes regularly. :)

  • @thedragoncorpse6403
    @thedragoncorpse6403 4 года назад

    please tell me why do we use clone method instead of just copying the reference from older to newer like
    Bookshop bs1=bs;

  • @arpitmehta9655
    @arpitmehta9655 7 лет назад

    Thanks sir :) for assisting

  • @sakuragi1111
    @sakuragi1111 3 года назад

    Book added into the new book shop is still the reference.

  • @pankajmenkudale
    @pankajmenkudale 6 лет назад

    will you upload more video on design pattern ?

  • @rajivraghu9857
    @rajivraghu9857 7 лет назад

    pls do all design pattern video. Thanks Navin

  • @munirali137
    @munirali137 5 лет назад

    Thank you

  • @louaykhammar7268
    @louaykhammar7268 3 года назад

    thanks

  • @vyshnavramesh9305
    @vyshnavramesh9305 5 лет назад +3

    guyz this is wrong..the shallow cloning part. Whats the use of an incorrect info tutorial?

  • @abdollahsobhy9743
    @abdollahsobhy9743 6 лет назад

    Hi, Thanks for your effort. I just face a problem with the code. It gives me NullPointerException in the clone method at this line (bookShop.getBooks().add(b);). What is the problem?

  • @manjusha9630
    @manjusha9630 4 года назад

    plz do facade design pattern

  • @kaoushikkumar8472
    @kaoushikkumar8472 4 года назад

    Hi Navin,
    Could we have small demo for the same using Python code? It is desperately required by the users like me.

  • @ramyashanthisalugu4758
    @ramyashanthisalugu4758 6 лет назад

    Can't we just assign bs1 = bs and if we want a different bookshop name just set it as bs1.setShopName()

  • @murugadossarumugam7031
    @murugadossarumugam7031 7 лет назад +1

    It cannot be cloning...you are again calling the database while cloning

  • @venkatk7914
    @venkatk7914 5 лет назад

    nice vedio

  • @sachinbhise4074
    @sachinbhise4074 4 года назад

    instead of creation new object directly you are creation new object in clone method.

  • @aslam3161
    @aslam3161 5 лет назад +2

    wrong

  • @pratikchauhan6077
    @pratikchauhan6077 7 лет назад

    sir can you make a video in jsp with hibernate then clone object
    please sir give me this type of tutorial

  • @SantoshKumar-yg7rc
    @SantoshKumar-yg7rc 7 лет назад +2

    explanation is simply confusing for even some one who knows the dp.

  • @brijgarg6178
    @brijgarg6178 4 года назад +1

    Demo of shallow copy is wrong. Please corrct the video. Otherwise people will learn it in a wrong way

  • @madhuridhadi6492
    @madhuridhadi6492 6 лет назад +3

    Hi Sir,
    Your explanation for shallow copy is not correct. You are saying that shallow copy does not create a new object instead assigns the reference of the cloned object which is not correct. Shallow copy do create a new object.

  • @thereviewer9947
    @thereviewer9947 6 лет назад

    Hi Navin! Your videos are good and you are doing a great job.
    But when it comes to this video, this is totally wrong example.
    You can verify this by commenting the custom cloning code and using the default .clone method!!

  • @shaswatkumar1234
    @shaswatkumar1234 7 лет назад +2

    Its clear. but you are confusing me by taking the example of different type of cloning. I think it does not matter to go for 2nd type.

  • @dhirajpatil6431
    @dhirajpatil6431 6 лет назад

    Not understand shallow and deep cloning difference... It's not clear by this example

  • @polojoy6824
    @polojoy6824 5 лет назад

    thank q

  • @isoplayers
    @isoplayers 6 лет назад

    the beeping in the background drove me nuts...

  • @sumitkawale9878
    @sumitkawale9878 3 года назад

    I've new name now.
    let me introduce myself,
    I am Alien👽

  • @ashokselvaraj8152
    @ashokselvaraj8152 4 года назад

    Liked

  • @epicghost9222
    @epicghost9222 4 года назад

    Deep cloning explaination or example given is wrong. please correct it in new video.
    What you explained is shallow copy both the time.

  • @Ravikumar-gj6qw
    @Ravikumar-gj6qw 5 лет назад

    Not explained properly

  • @Charan1990ify
    @Charan1990ify 7 лет назад +1

    This is worst !!

  • @krishnakrishna-yh9ly
    @krishnakrishna-yh9ly 4 года назад

    aliens, why?

  • @wasimpatel2618
    @wasimpatel2618 Год назад

    navin sir, if you havnt understood any concept completely ,please dont make videoson that.

  • @Xenon77x
    @Xenon77x 5 лет назад

    BookShop bullshit = new BookShop();
    im i the only one who thought of this ?

  • @ChandrachurMukherjee96
    @ChandrachurMukherjee96 5 лет назад

    pretty clumsy.. LOL

  • @arafathossain1803
    @arafathossain1803 3 года назад

    So funny! BS :v

  • @benoitgoldenberg777
    @benoitgoldenberg777 7 лет назад +1

    Java is dead, long live Scala !!!

    • @sushilveerdhwaj
      @sushilveerdhwaj 7 лет назад +1

      Everything is mutable except String in JAVA...sorry for your SCALA,,it will dead soon!!!

    • @chnrbk1
      @chnrbk1 6 лет назад +1

      Never. billions of devices running in Java

    • @vishalaher8286
      @vishalaher8286 5 лет назад

      i think they just do programming they don't know about what is going on

  • @jackfrost8969
    @jackfrost8969 8 месяцев назад

    This was a waste.

  • @hrs7305
    @hrs7305 2 года назад

    You can implement deep copy with object clone method as well
    protected Object clone() throws CloneNotSupportedException {
    BookShop bs = new BookShop();
    bs.setName(this.getName());
    bs.books = (List)this.getBooks().clone(); // saves us from writing a for loop by deep copying a list
    return bs;
    }

  • @charankumar6942
    @charankumar6942 5 лет назад

    You are aweome Navin.. I like your live programing skills with fastness and help us to learn the concept and also live coding, test the code and debug.. Awesome videos..Thanks

  • @chandankumar-su7ng
    @chandankumar-su7ng 4 года назад

    thank you sir

  • @epicghost9222
    @epicghost9222 4 года назад

    Deep cloning explaination or example given is wrong. please correct it in new video.
    What you explained is shallow copy both the time.

  • @epicghost9222
    @epicghost9222 4 года назад +1

    Deep cloning explaination or example given is wrong. please correct it in new video.
    What you explained is shallow copy both the time.

  • @epicghost9222
    @epicghost9222 4 года назад

    Deep cloning explaination or example given is wrong. please correct it in new video.
    What you explained is shallow copy both the time.