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
I have been called a lot of things in my life , never been called a Alien ...
@mohan-ri6ze
3 жыл бұрын
He thinks he have subscribers from other planets also
@vimalbhatt5359
Жыл бұрын
He is from Pluto that's why we are aliens to him
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
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
4 жыл бұрын
@@maolyherrera4240 Better way is use clone() in Book
@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
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
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();
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
6 жыл бұрын
You are correct
@satwikpeddireddy9639
6 жыл бұрын
yeah i got the same doubt
@niksgupta36
5 жыл бұрын
Correct!
@Ravikumar-gj6qw
5 жыл бұрын
Your correct bro
@shaikhrameezahmed4213
4 жыл бұрын
Absolutely.
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
i love the way you make everything simple and cooler :)
your way of teaching is improving day by day...I am watching your videos when u have other channel name naveen reddy
Great work, keep it up !!
Awesome tutorial video, Thanks Sir
can you make more of this, really appreciating your videos!
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.
You are a awesome teacher
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 ?
Hi Navin, I you have excellent ability to explain things in very simple way.
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?
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?
Very well thoughtfully explained
Thanks sir :) for assisting
at 13.05 .. you are first removing object book-3 and then cloning so its affecting both BookShops.. not because of shallow copy
I really love your explanations. Why didn't you cover all design patterns?
please tell me why do we use clone method instead of just copying the reference from older to newer like Bookshop bs1=bs;
thanks a lot naveen sir
This is very useful..
Awesome work by another indian .
is Use of prototype design pattern with factory Pattern good approach ?
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
pls do all design pattern video. Thanks Navin
Nice explaination.
Hi Navin, Could we have small demo for the same using Python code? It is desperately required by the users like me.
What about immutable obj do we need copies of that. If not why?
sir can you make a video in jsp with hibernate then clone object please sir give me this type of tutorial
will you upload more video on design pattern ?
thanks for you great vedio
awesome explanation !!!! The only thing is playback speed is a little faster.
Thank you Sir
If we are creating another object inside clone method is it really prototyping ?
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.
How implementation of Cloneable given permission to class to add clone method, can you clarify more on this.
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
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!
Can't we just assign bs1 = bs and if we want a different bookshop name just set it as bs1.setShopName()
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
Thank you
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?
thank you sir
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
7 жыл бұрын
Yes you can say that...
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?
Nice explained
@kbhardwaj1989
5 жыл бұрын
Mr KMD, you watched this video very late. Naveen sir has shared this video 1 year back. Do follow his vidoes regularly. :)
Thanks!
his head shines brighter than my life
@ytpreytpre4283
4 жыл бұрын
lol
plz do facade design pattern
Are you not doing the swallow copy of the objects in the loop? You should have written list.add(b.clone())
Navin's videos should not have a dislike button / it's useless :)
nice vedio
thanks
Book added into the new book shop is still the reference.
thank q
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!!
navin reddy bhagwan. jay ho kaka
Mistake in 13:36 time. In order to demonstrate shallow cloning you had to remove an element after calling clone() method. Not before
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.
the beeping in the background drove me nuts...
It cannot be cloning...you are again calling the database while cloning
guyz this is wrong..the shallow cloning part. Whats the use of an incorrect info tutorial?
@kathiravanjagadeesan
5 жыл бұрын
Nothing is perfect ,so forgive
@imtech55
5 жыл бұрын
Exactly. He is not explaining properly.
Not understand shallow and deep cloning difference... It's not clear by this example
explanation is simply confusing for even some one who knows the dp.
instead of creation new object directly you are creation new object in clone method.
Liked
Deep cloning explaination or example given is wrong. please correct it in new video. What you explained is shallow copy both the time.
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.
Demo of shallow copy is wrong. Please corrct the video. Otherwise people will learn it in a wrong way
I've new name now. let me introduce myself, I am Alien👽
This one was little confusing.
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.
wrong
Not explained properly
pretty clumsy.. LOL
aliens, why?
So funny! BS :v
BookShop bullshit = new BookShop(); im i the only one who thought of this ?
This is worst !!
navin sir, if you havnt understood any concept completely ,please dont make videoson that.
Java is dead, long live Scala !!!
@sushilveerdhwaj
7 жыл бұрын
Everything is mutable except String in JAVA...sorry for your SCALA,,it will dead soon!!!
@chnrbk1
6 жыл бұрын
Never. billions of devices running in Java
@vishalaher8286
5 жыл бұрын
i think they just do programming they don't know about what is going on
@tusharshekhar2113
5 жыл бұрын
so its two years since you commented this and it is still number 1 programming language , though I use Scala a lot
This was a waste.
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; }
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
Deep cloning explaination or example given is wrong. please correct it in new video. What you explained is shallow copy both the time.
Deep cloning explaination or example given is wrong. please correct it in new video. What you explained is shallow copy both the time.
Deep cloning explaination or example given is wrong. please correct it in new video. What you explained is shallow copy both the time.