Prototype Design Pattern in Java

Ғылым және технология

Recommended Book :
Head First Design Pattern : amzn.to/2pY5xbR
Prototype Design Pattern in Java
This video contains both theory and practical session.
Prototype design pattern belongs to Creational design pattern which belongs to Design Patterns in java.
Prototype pattern refers to creating duplicate object while keeping performance in mind.
Trainer: Navin Reddy
Check out our website: www.telusko.com
Follow Telusko on Twitter: / navinreddy20
Follow on Facebook:
Telusko : / teluskolearnings
Navin Reddy : / navintelusko
Follow Navin Reddy on Instagram: / navinreddy20
Subscribe to our other channel:
Navin Reddy : / @navinreddy
Telusko Hindi :
/ @teluskohindi
Subscribe to the channel and learn Programming in easy way.
Java Tutorial for Beginners : goo.gl/p10QfB
Scala Tutorials for Java Developers : goo.gl/8H1aE5
C Tutorial Playlist : goo.gl/8v92pu
Android Tutorial for Beginners Playlist : goo.gl/MzlIUJ
XML Tutorial : goo.gl/Eo79do
Design Patterns in Java : goo.gl/Kd2MWE
Java Servlet : goo.gl/R5nHp8
Hibernate Tutorial :goo.gl/N5ONYg
Spring MVC Tutorial : goo.gl/9ubbG2
OpenShift Tutorial for Beginners : goo.gl/s58BQH
Spring Framework with Maven : goo.gl/MaEluO
Sql Tutorial for Beginners : goo.gl/x3PrTg
String Handling in Java : goo.gl/zUdPwa
Array in Java : goo.gl/uXTaUy
Socket Programming in Java : goo.gl/jlMEbg
Exception Handling in Java : goo.gl/N4NbAW
Regards,
Navin Reddy

Пікірлер: 117

  • @Ranjith_P
    @Ranjith_P6 жыл бұрын

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

  • @mohan-ri6ze

    @mohan-ri6ze

    3 жыл бұрын

    He thinks he have subscribers from other planets also

  • @vimalbhatt5359

    @vimalbhatt5359

    Жыл бұрын

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

  • @paranjisridhar5529
    @paranjisridhar55296 жыл бұрын

    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 жыл бұрын

    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 жыл бұрын

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

  • @it-family-

    @it-family-

    3 жыл бұрын

    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 жыл бұрын

    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();

  • @mishamovdivar
    @mishamovdivar7 жыл бұрын

    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))

  • @TheDibyendusarkar

    @TheDibyendusarkar

    6 жыл бұрын

    You are correct

  • @satwikpeddireddy9639

    @satwikpeddireddy9639

    6 жыл бұрын

    yeah i got the same doubt

  • @niksgupta36

    @niksgupta36

    5 жыл бұрын

    Correct!

  • @Ravikumar-gj6qw

    @Ravikumar-gj6qw

    5 жыл бұрын

    Your correct bro

  • @shaikhrameezahmed4213

    @shaikhrameezahmed4213

    4 жыл бұрын

    Absolutely.

  • @naveengamini3445
    @naveengamini34455 жыл бұрын

    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

  • @sakshisharma7097
    @sakshisharma70977 жыл бұрын

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

  • @sandhyaaa24
    @sandhyaaa247 жыл бұрын

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

  • @vladimirjevremov5581
    @vladimirjevremov55817 жыл бұрын

    Great work, keep it up !!

  • @buzzbummer2111
    @buzzbummer21115 жыл бұрын

    Awesome tutorial video, Thanks Sir

  • @vnm_8945
    @vnm_89455 жыл бұрын

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

  • @SunilKumar-pd9eh
    @SunilKumar-pd9eh6 жыл бұрын

    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.

  • @liponrr9737
    @liponrr97377 жыл бұрын

    You are a awesome teacher

  • @rithikraj4316
    @rithikraj431612 сағат бұрын

    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 ?

  • @amitkhandey3582
    @amitkhandey35822 жыл бұрын

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

  • @ujjawalgupta5408
    @ujjawalgupta54083 жыл бұрын

    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?

  • @abdollahsobhy9743
    @abdollahsobhy97436 жыл бұрын

    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?

  • @vinaysingh2971
    @vinaysingh29713 жыл бұрын

    Very well thoughtfully explained

  • @arpitmehta9655
    @arpitmehta96557 жыл бұрын

    Thanks sir :) for assisting

  • @tusharkale9578
    @tusharkale9578 Жыл бұрын

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

  • @jasper5016
    @jasper5016 Жыл бұрын

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

  • @thedragoncorpse6403
    @thedragoncorpse64034 жыл бұрын

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

  • @aashishgoyal1436
    @aashishgoyal14366 жыл бұрын

    thanks a lot naveen sir

  • @ranilutube
    @ranilutube6 жыл бұрын

    This is very useful..

  • @kathiravanjagadeesan
    @kathiravanjagadeesan5 жыл бұрын

    Awesome work by another indian .

  • @asheeshpratapsingh4948
    @asheeshpratapsingh49486 жыл бұрын

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

  • @noahvo6673
    @noahvo66733 жыл бұрын

    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

  • @rajivraghu9857
    @rajivraghu98577 жыл бұрын

    pls do all design pattern video. Thanks Navin

  • @swatiyadav9842
    @swatiyadav98424 жыл бұрын

    Nice explaination.

  • @kaoushikkumar8472
    @kaoushikkumar84724 жыл бұрын

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

  • @yatri6329
    @yatri63292 жыл бұрын

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

  • @pratikchauhan6077
    @pratikchauhan60777 жыл бұрын

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

  • @pankajmenkudale
    @pankajmenkudale5 жыл бұрын

    will you upload more video on design pattern ?

  • @mermerjamal6662
    @mermerjamal6662 Жыл бұрын

    thanks for you great vedio

  • @myangelsworld6566
    @myangelsworld65665 ай бұрын

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

  • @srinivasjava1932
    @srinivasjava19324 жыл бұрын

    Thank you Sir

  • @abhilash1755
    @abhilash1755 Жыл бұрын

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

  • @user-lx7gf8kn3n
    @user-lx7gf8kn3n10 ай бұрын

    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.

  • @rajsaraogi
    @rajsaraogi Жыл бұрын

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

  • @hardstuck170
    @hardstuck1707 жыл бұрын

    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. 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!

  • @ramyashanthisalugu4758
    @ramyashanthisalugu47585 жыл бұрын

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

  • @rakshamalviya3450
    @rakshamalviya34504 жыл бұрын

    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

  • @munirali137
    @munirali1374 жыл бұрын

    Thank you

  • @niteshagarwal4934
    @niteshagarwal49344 жыл бұрын

    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?

  • @chandankumar-su7ng
    @chandankumar-su7ng4 жыл бұрын

    thank you sir

  • @vigneshv1517
    @vigneshv15177 жыл бұрын

    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??

  • @NavinReddyJava

    @NavinReddyJava

    7 жыл бұрын

    Yes you can say that...

  • @arindamsarkar3383
    @arindamsarkar33832 жыл бұрын

    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?

  • @kumodsharma8141
    @kumodsharma81415 жыл бұрын

    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. :)

  • @PostMapping
    @PostMapping2 жыл бұрын

    Thanks!

  • @xenon4602
    @xenon46024 жыл бұрын

    his head shines brighter than my life

  • @ytpreytpre4283

    @ytpreytpre4283

    4 жыл бұрын

    lol

  • @manjusha9630
    @manjusha96304 жыл бұрын

    plz do facade design pattern

  • @gouraharidas
    @gouraharidas Жыл бұрын

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

  • @cristianflorentintarta885
    @cristianflorentintarta885 Жыл бұрын

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

  • @venkatk7914
    @venkatk79145 жыл бұрын

    nice vedio

  • @louaykhammar7268
    @louaykhammar72682 жыл бұрын

    thanks

  • @sakuragi1111
    @sakuragi11113 жыл бұрын

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

  • @polojoy6824
    @polojoy68244 жыл бұрын

    thank q

  • @thereviewer9947
    @thereviewer99476 жыл бұрын

    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!!

  • @prathammodii
    @prathammodii Жыл бұрын

    navin reddy bhagwan. jay ho kaka

  • @JafarAliyev
    @JafarAliyev8 ай бұрын

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

  • @sanjeen2503
    @sanjeen2503 Жыл бұрын

    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.

  • @isoplayers
    @isoplayers5 жыл бұрын

    the beeping in the background drove me nuts...

  • @murugadossarumugam7031
    @murugadossarumugam70317 жыл бұрын

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

  • @vyshnavramesh9305
    @vyshnavramesh93055 жыл бұрын

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

  • @kathiravanjagadeesan

    @kathiravanjagadeesan

    5 жыл бұрын

    Nothing is perfect ,so forgive

  • @imtech55

    @imtech55

    5 жыл бұрын

    Exactly. He is not explaining properly.

  • @dhirajpatil6431
    @dhirajpatil64316 жыл бұрын

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

  • @SantoshKumar-yg7rc
    @SantoshKumar-yg7rc7 жыл бұрын

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

  • @sachinbhise4074
    @sachinbhise40744 жыл бұрын

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

  • @ashokselvaraj8152
    @ashokselvaraj81524 жыл бұрын

    Liked

  • @epicghost9222
    @epicghost92223 жыл бұрын

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

  • @madhuridhadi6492
    @madhuridhadi64926 жыл бұрын

    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.

  • @brijgarg6178
    @brijgarg61784 жыл бұрын

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

  • @sumitkawale9878
    @sumitkawale98783 жыл бұрын

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

  • @tusharshekhar2113
    @tusharshekhar21135 жыл бұрын

    This one was little confusing.

  • @shaswatkumar1234
    @shaswatkumar12347 жыл бұрын

    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.

  • @aslam3161
    @aslam31615 жыл бұрын

    wrong

  • @Ravikumar-gj6qw
    @Ravikumar-gj6qw5 жыл бұрын

    Not explained properly

  • @ChandrachurMukherjee96
    @ChandrachurMukherjee965 жыл бұрын

    pretty clumsy.. LOL

  • @krishnakrishna-yh9ly
    @krishnakrishna-yh9ly3 жыл бұрын

    aliens, why?

  • @arafathossain1803
    @arafathossain18033 жыл бұрын

    So funny! BS :v

  • @xenon4602
    @xenon46024 жыл бұрын

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

  • @Charan1990ify
    @Charan1990ify7 жыл бұрын

    This is worst !!

  • @wasimpatel2618
    @wasimpatel261811 ай бұрын

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

  • @benoitgoldenberg777
    @benoitgoldenberg7777 жыл бұрын

    Java is dead, long live Scala !!!

  • @sushilveerdhwaj

    @sushilveerdhwaj

    7 жыл бұрын

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

  • @chnrbk1

    @chnrbk1

    6 жыл бұрын

    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

  • @tusharshekhar2113

    @tusharshekhar2113

    5 жыл бұрын

    so its two years since you commented this and it is still number 1 programming language , though I use Scala a lot

  • @jackfrost8969
    @jackfrost89694 ай бұрын

    This was a waste.

  • @hrs7305
    @hrs73052 жыл бұрын

    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
    @charankumar69425 жыл бұрын

    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

  • @epicghost9222
    @epicghost92223 жыл бұрын

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

  • @epicghost9222
    @epicghost92223 жыл бұрын

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

  • @epicghost9222
    @epicghost92223 жыл бұрын

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

Келесі