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