Тёмный

Prototype Design Pattern in Java 

Telusko
Подписаться 2,4 млн
Просмотров 145 тыс.
50% 1

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

Наука

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 116   
@mishamovdivar
@mishamovdivar 7 лет назад
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.
@Ranjith_P
@Ranjith_P 6 лет назад
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 2 года назад
He is from Pluto that's why we are aliens to him
@paranjisridhar5529
@paranjisridhar5529 6 лет назад
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- 4 года назад
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();
@SunilKumar-pd9eh
@SunilKumar-pd9eh 7 лет назад
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.
@amitkhandey3582
@amitkhandey3582 2 года назад
Hi Navin, I you have excellent ability to explain things in very simple way.
@hardstuck170
@hardstuck170 7 лет назад
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!
@ujjawalgupta5408
@ujjawalgupta5408 4 года назад
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?
@vinaysingh2971
@vinaysingh2971 3 года назад
Very well thoughtfully explained
@rakshamalviya3450
@rakshamalviya3450 5 лет назад
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
@vigneshv1517
@vigneshv1517 7 лет назад
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...
@vishaldindalkop294
@vishaldindalkop294 21 день назад
Thank you for the video
@vladimirjevremov5581
@vladimirjevremov5581 7 лет назад
Great work, keep it up !!
@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;
@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?
@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 2 года назад
Navin's videos should not have a dislike button / it's useless :)
@asheeshpratapsingh4948
@asheeshpratapsingh4948 6 лет назад
is Use of prototype design pattern with factory Pattern good approach ?
@xenon4602
@xenon4602 4 года назад
his head shines brighter than my life
@ytpreytpre4283
@ytpreytpre4283 4 года назад
lol
@swatiyadav9842
@swatiyadav9842 4 года назад
Nice explaination.
@rajivraghu9857
@rajivraghu9857 7 лет назад
pls do all design pattern video. Thanks Navin
@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.
@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.
@mermerjamal6662
@mermerjamal6662 Год назад
thanks for you great vedio
@JafarAliyev
@JafarAliyev 10 месяцев назад
Mistake in 13:36 time. In order to demonstrate shallow cloning you had to remove an element after calling clone() method. Not before
@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.
@srinivasjava1932
@srinivasjava1932 4 года назад
Thank you Sir
@ramyashanthisalugu4758
@ramyashanthisalugu4758 5 лет назад
Can't we just assign bs1 = bs and if we want a different bookshop name just set it as bs1.setShopName()
@munirali137
@munirali137 5 лет назад
Thank you
@prathammodii
@prathammodii Год назад
navin reddy bhagwan. jay ho kaka
@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. :)
@brijgarg6178
@brijgarg6178 4 года назад
Demo of shallow copy is wrong. Please corrct the video. Otherwise people will learn it in a wrong way
@murugadossarumugam7031
@murugadossarumugam7031 7 лет назад
It cannot be cloning...you are again calling the database while cloning
@aslam3161
@aslam3161 5 лет назад
wrong
@SantoshKumar-yg7rc
@SantoshKumar-yg7rc 7 лет назад
explanation is simply confusing for even some one who knows the dp.
@dhirajpatil6431
@dhirajpatil6431 6 лет назад
Not understand shallow and deep cloning difference... It's not clear by this example
@sachinbhise4074
@sachinbhise4074 4 года назад
instead of creation new object directly you are creation new object in clone method.
@sumitkawale9878
@sumitkawale9878 3 года назад
I've new name now. let me introduce myself, I am Alien👽
@Ravikumar-gj6qw
@Ravikumar-gj6qw 5 лет назад
Not explained properly
@Charan1990ify
@Charan1990ify 7 лет назад
This is worst !!
@wasimpatel2618
@wasimpatel2618 Год назад
navin sir, if you havnt understood any concept completely ,please dont make videoson that.
@xenon4602
@xenon4602 5 лет назад
BookShop bullshit = new BookShop(); im i the only one who thought of this ?
@jackfrost8969
@jackfrost8969 6 месяцев назад
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; }
@rithikraj4316
@rithikraj4316 2 месяца назад
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 ?
@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.
@vyshnavramesh9305
@vyshnavramesh9305 5 лет назад
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.
@noahvo6673
@noahvo6673 3 года назад
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
@jasper5016
@jasper5016 Год назад
I really love your explanations. Why didn't you cover all design patterns?
@naveengamini3445
@naveengamini3445 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
@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
@liponrr9737
@liponrr9737 7 лет назад
You are a awesome teacher
@sakshisharma7097
@sakshisharma7097 7 лет назад
i love the way you make everything simple and cooler :)
@arafathossain1803
@arafathossain1803 3 года назад
So funny! BS :v
@louaykhammar7268
@louaykhammar7268 3 года назад
thanks
@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.
@rajsaraogi
@rajsaraogi 2 года назад
How implementation of Cloneable given permission to class to add clone method, can you clarify more on this.
@myangelsworld6566
@myangelsworld6566 7 месяцев назад
awesome explanation !!!! The only thing is playback speed is a little faster.
@abhilash1755
@abhilash1755 Год назад
If we are creating another object inside clone method is it really prototyping ?
@madhuridhadi6492
@madhuridhadi6492 6 лет назад
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.
@niteshagarwal4934
@niteshagarwal4934 4 года назад
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?
@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?
@sakuragi1111
@sakuragi1111 3 года назад
Book added into the new book shop is still the reference.
@ChandrachurMukherjee96
@ChandrachurMukherjee96 5 лет назад
pretty clumsy.. LOL
@kathiravanjagadeesan
@kathiravanjagadeesan 5 лет назад
Awesome work by another indian .
@krishnakrishna-yh9ly
@krishnakrishna-yh9ly 4 года назад
aliens, why?
@pratikchauhan6077
@pratikchauhan6077 7 лет назад
sir can you make a video in jsp with hibernate then clone object please sir give me this type of tutorial
@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!!
@chandankumar-su7ng
@chandankumar-su7ng 4 года назад
thank you sir
@PostMapping
@PostMapping 2 года назад
Thanks!
@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
@ashokselvaraj8152
@ashokselvaraj8152 4 года назад
Liked
@polojoy6824
@polojoy6824 5 лет назад
thank q
@ranilutube
@ranilutube 6 лет назад
This is very useful..
@aashishgoyal1436
@aashishgoyal1436 6 лет назад
thanks a lot naveen sir
@isoplayers
@isoplayers 6 лет назад
the beeping in the background drove me nuts...
@pankajmenkudale
@pankajmenkudale 6 лет назад
will you upload more video on design pattern ?
@buzzbummer2111
@buzzbummer2111 5 лет назад
Awesome tutorial video, Thanks Sir
@sandhyaaa24
@sandhyaaa24 7 лет назад
your way of teaching is improving day by day...I am watching your videos when u have other channel name naveen reddy
@shaswatkumar1234
@shaswatkumar1234 7 лет назад
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.
@venkatk7914
@venkatk7914 5 лет назад
nice vedio
@vnm_8945
@vnm_8945 6 лет назад
can you make more of this, really appreciating your videos!
@arpitmehta9655
@arpitmehta9655 7 лет назад
Thanks sir :) for assisting
@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 года назад
Deep cloning explaination or example given is wrong. please correct it in new video. What you explained is shallow copy both the time.
@benoitgoldenberg777
@benoitgoldenberg777 7 лет назад
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
Далее
Observer Design Pattern in Java
14:34
Просмотров 172 тыс.
Composite Design Pattern Practical
17:04
Просмотров 110 тыс.
Kenji's Sushi Shop Showdown - Brawl Stars Animation
01:55
Qalpoq - Amakivachcha (hajviy ko'rsatuv)
41:44
Просмотров 176 тыс.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
The State Design Pattern in Python Explained
19:14
Просмотров 76 тыс.
What is the Prototype Design Pattern?
7:48
Просмотров 10 тыс.
Design patterns in React
14:37
Просмотров 165 тыс.
Observer Pattern - Design Patterns (ep 2)
49:47
Просмотров 565 тыс.
Самый дорогой iPHONE 16 PRO MAX #shorts
0:58