kzbin.info/www/bejne/e3KymImFj890iZY factory pattern in .net and .net core
@derekbanas11 жыл бұрын
You use the Factory design pattern when you want to define the class of an object at runtime. It also allows you to encapsulate object creation so that you can keep all object creation code in one place. The abstract pattern just makes more complex objects
@voidpointer3984 ай бұрын
still helping developers after 11 years amazing video
@Jehan9910011 жыл бұрын
I am studying for an interview as a Senior Java Developer and I found these to be very helpful. I am sure I learned all this before but it is a nice refresher since I do not always use them every day at work and I have a bad memory. Thanks Derek, we really appreciate this service you provide.
@justintorre6944 жыл бұрын
This tutorial was made so long ago but is still so perfect
@teratoma.3 жыл бұрын
what do u mean long ago??? 8 years ago was 2 years ago
@jojokuki97013 жыл бұрын
"long ago"... very relative
@derekbanas12 жыл бұрын
I eat egg beaters (Egg Whites) now and again. I purely eat this way because I try to be healthy and I really don't like meat. I never liked eating it. I don't have anything against anyone that hunts. When I was little I had to eat deer meat to survive. Thankfully now I can eat what I want :)
@kitsurubami4 жыл бұрын
60 seconds into the video and you already explained it so much better than any other resource i have seen so far. and i have watched a ton of them. thank you!
@derekbanas4 жыл бұрын
Thank you for the compliment I'm happy I could help
@sodatta1111 жыл бұрын
The best thing about your tutorials is that they are precise. That prevents any kind of confusion.. Sometimes I rewind a bit to pick the pace, but over all your lessons are very well imprinted in the viewer's mind. Great Work!
@NC-ps2ck10 жыл бұрын
I just wanted to say that when you outline the basic info in text in the beginning, that is extremely helpful. I'm the type of person who likes to get the gist of something aside from textbook descriptions, and those brief and concise intros are awesome. Thank you very much.
@derekbanas12 жыл бұрын
You're very welcome :) It is very nice to be able to help people all over the world. I'm glad you liked the video
@Razorrr163 жыл бұрын
Congrats on this video because you made it very clear and simple! 🙌 However I'd like to make some notes that can help understand this best to new coders: 1. Encapsulating the decision making of what EnemyShip to create in the Factory, you avoid duplication of code (yes, youd said it). But I can imagine coders thinking "WHERE!?". Well if you don't do it in the Factory class, then you are gonna put that logic in every place that you may need to create an EnemyShip, such as the main() method you used in the first example. 2. Another benefit is that inside the factory method you can handle exceptions, such as when the string passed to choose the concrete EnemyShip is invalid, you can for instance throw an IllegalArgumentException. If needed you can catch that exception in the client class (ie: the class using the factory) or maybe just throw a RuntimeException. Hope it helps!
@tivmego11 жыл бұрын
I have not watched all of your DP tutorials but if the method of teaching used here is the same applied all through the tutorial, then you have won my heart and time. I want to thank you for your time. God bless you!
@Lukomeyan9 жыл бұрын
I see there are quite a few negative comments. I believe the point of this tutorial is to demonstrate use of the factory pattern. Sometimes when you need to illustrate certain aspects of programming you need to skip a few things and ignore "style" and other factors as you're on a clock when creating a video. I believe the factory pattern is brought across quite well in this video and it really helped me understand it.
@derekbanas9 жыл бұрын
+Luke Slywalker Thank you very much for the compliment :) i appreciate it.
@derekbanas11 жыл бұрын
Yes that is where the design patterns came from. They were great solutions for common problems that eventually people started writing down.
@derekbanas11 жыл бұрын
I'm glad you are enjoying the videos :)
@abolfazlsaravani22142 жыл бұрын
every once in a while I come here to refresh my memory. it is fast and concise. after all these years, still one of the best for design patterns.
@derekbanas11 жыл бұрын
You are very welcome :) thanks for taking the time to say you liked it
@derekbanas11 жыл бұрын
If you are dealing with many data formats a facade may help you hide that complexity. A factory may help if you need to create many instances for each file format. An adapter may also help you deal with incompatible interfaces? It all depends on what your dealing with. I hope that helps?
@derekbanas11 жыл бұрын
Thank you :) I'm planning on making an advanced algorithms tutorial that will be covered as I continue making Android tutorials. I'm planning on covering a bunch of topics other then Android over the next few months including C, C++, JEE Topics, Advanced Algorithms, Ruby and some random psychology topics people have been asking for
@dhammond24910 жыл бұрын
Good tutorial. No fluffing around, no waiting for someone to slow type out everything, only important information explained precisely. Nice stuff
@derekbanas10 жыл бұрын
Thank you for all the nice compliments :)
@johnesco11 жыл бұрын
So I just started Ruby and ran into this same issue. I had lots of if-elses to control what got created and how and started to run into maintainability issues. The ideas here were general enough to be applicable to almost any (possibly all?) OO based languages. Thanks so much for posting this!
@derekbanas12 жыл бұрын
The diet I created helped me to lose over 80 pounds. It focused on quantity over calories. That forced me to find low calorie / low fat / low sodium alternatives for everything. I've never eaten factory produced meat so I have no idea what it tastes like luckily :) I've seen the videos and agree the process is both terrible for the animals as well as for those who eat the food, but I always try to avoid judging. I agree that regular eggs are way better :D
@justfair41817 жыл бұрын
I will anwser some questions though. A Simple Factory pattern is one that returns an instance of one of several possible classes, depending on the data provided to it. Usually all of the classes it returns have a common parent class and common methods, but each of them performs a task differently and is optimized for different kinds of data. The Factory Method pattern is a clever but subtle extension of this idea, where no single class makes the decision as to which subclass to instantiate. Instead, the superclass defers the decision to each subclass. This pattern does not actually have a decision point where one subclass is directly selected over another class. Instead, programs written to this pattern define an abstract class that creates objects but lets each subclass decide which object to create.
@derekbanas11 жыл бұрын
Thank you :) I'm experimenting with new ways to teach so that information sticks in the brain. I'm glad you enjoy the videos.
@derekbanas11 жыл бұрын
Thank you :) I did my best to make the tutorials easy to grasp so they could be applied to other languages. Thank you for telling me I succeeded.
@tibimose8238 жыл бұрын
Super cool. I just wrote in about 2 hours a random football commentary. I made classes : Player, Team and TeamFactory (+some particular teams classes) and now the player can pass and shoot. This is so cool because after you implement it, you only have to add stuff and it doesn't break anything. Thank you!!
@derekbanas8 жыл бұрын
That's awesome! I'm happy I could help. I love making little fake people in my computer and then just watch them live in there :)
@tibimose8238 жыл бұрын
I'm really curious what are your thoughts on this implementation of the factory: public class TeamFactory { public Team createTeam (Class
@derekbanas11 жыл бұрын
You're very welcome :) Thank you for taking the time to say you liked it
@khanasfireza95154 жыл бұрын
I have used these design patterns, figured some of them myself, but never knew these had names before watching this video. But great playlist learned some new design patterns which I think will help me in my upcoming projects. Thank you so much, sir.
@derekbanas4 жыл бұрын
I’m happy I could help :)
@derekbanas11 жыл бұрын
You're very welcome :) Thank you for taking the time to tell me you like the videos.
@derekbanas12 жыл бұрын
I was for a few months, but my body couldn't handle it. I used to get very jumpy all of the time. If you go completely raw your body processes the food very quickly which a least in me caused stress. If you are an athlete I'd highly recommend it, but it didn't work for me. I only eat grains, veggies and cheese. I could never give up cheese :) No sweets either
@derekbanas12 жыл бұрын
If you created a subclass with a method that is only in the subclass and not in the super class you wouldn't be able to access that method by referring the subclass as the super class using polymorphism. Technically you could with reflection, but I'm ignoring that for now. You may want to look at my reflection tutorial? I bet it will open the world to you, but just understand it isn't considered a good idea to use reflection very often. It is very powerful, but confusing to some people
@derekbanas11 жыл бұрын
My number one goal is to make complex topics easy to understand. Thank you very much for telling me that I succeeded! You're very welcome :)
@hullyoung5 жыл бұрын
super helpful, I love your approach where you explain the 'bad' approach first then explain 'good' way to implement the same functionality with factory pattern.
@derekbanas5 жыл бұрын
Thank you :) I'm happy you are enjoying the DP videos
@elfusortega11 жыл бұрын
I agree with Derek, while you could make it a Singleton pattern you would be adding more 'complexity' or 'semantics' to a single class, thus giving more responsabilities to a single class, and remember one of the best things to achieve better modularity (I can't think of a OOP definition) you need to have well defined responsabilities for each class.
@derekbanas11 жыл бұрын
Thank you :) I'm sorry, but a may not understand the question. This is just an example of using the factory method.EnemyShip is used only to be able to pass its subclasses so it is more dynamic
@derekbanas11 жыл бұрын
You're very welcome :) I do my best to make the topics interesting
@derekbanas11 жыл бұрын
Yes encapsulation and decoupling is the goal of the factory and many other patterns. I'm very happy to have helped :)
@derekbanas11 жыл бұрын
I'd follow the advice of your professor since he will decide on your grade :) I personally like to cover the patterns from the least complicated to the more complicated. I also like to structure them so that after you learn a concept in one pattern I like to reenforce it by using a similar pattern. The difference between me and professors is that I don't believe there are as many rules as they do. I hope that helps
@theismywedding7 жыл бұрын
Hey man, I am a student at the university of applied sciences in Rotterdam ( the netherlands ) and I would like to thank you from the bottom of my heart for all these amazing informative videos, they really help me out!
@derekbanas7 жыл бұрын
Thank you for taking the time to tell me that they helped :) I greatly appreciate that. It is also particularly cool that I'm helping people in other countries because I never travel. I feel like I'm seeing the world in some weird way :D
@JICH202810 жыл бұрын
Great video,thanks! According to headfirst, this is a simple factory pattern... Your voice is like a auctioneer. It is quick but very clear.
@derekbanas10 жыл бұрын
Jimmy Cheng You're very welcome :) I'm glad you liked it.
@vincentconrad92896 жыл бұрын
Why not supplying the class of the object, that should be created, to the factory and create the instance via Reflections? This way you could avoid these "bad code" if statements. You could also limit the factory to only accept Classes of your SuperType X via createIntance(Class
@jiabinchen659811 жыл бұрын
Your lecture is way better than tons of professors. thank you so much
@derekbanas11 жыл бұрын
You're very welcome :) yes I covered facade. It is on my KZbin channel in the design patterns playlist
@derekbanas12 жыл бұрын
You could call it immediately after creation. You could give every ship an id and then refer to it that way. You could cycle through all ships using an enhanced for. You could use reflection. There are many ways. Don't worry I'll be covering refactoring very soon and it will provide real world examples on when and how to use design patterns
@derekbanas11 жыл бұрын
Thank you :) I'm very happy i was able to succeed with what I aimed to do in this video. I'm glad you liked it
@mostinho74 жыл бұрын
Used to create instances of objects that share a superclass Type returned needs to be determined at runtime so we use factory. Centralizes the code that creates the objects 2:05 uml diagram
@derekbanas11 жыл бұрын
I'm very happy that you enjoyed it :) That was a little typo on my part. It would be better to say extends with the abstract class
@derekbanas11 жыл бұрын
I'm not sure what your asking in your first question. As per the second one it is ok to make it static, but you then won't be able to subclass
@jaimeogrady68436 жыл бұрын
You explain really well, have an easy to understand accent and your code is pretty clear. Thank you for sharing your knowledge!
@derekbanas6 жыл бұрын
Thank you very much :)
@derekbanas11 жыл бұрын
I'm glad you fixed it. Always feel free to ask questions :)
@koendemonie488311 жыл бұрын
EnemyShip newShip = null; that statement in your factory, you can remove that since you return the values directly instead of returning the newEnemyShip :)
@derekbanas11 жыл бұрын
You're very welcome :) It is very nice to be able to help so many nice people
@VectorMed11 жыл бұрын
Great tutorial. Really powerful to explain the concept, then step through code line by line to explain why someone would want to use it. I also appreciate that you took the time to edit out downtime in editing the code so you could explain this in much less time.
@derekbanas11 жыл бұрын
Yes that is the same thing
@derekbanas11 жыл бұрын
Thank you for taking the time to tell me the video helped :)
@derekbanas12 жыл бұрын
You're very welcome :) Thank you for the kind words
@derekbanas11 жыл бұрын
Not a problem. This stuff can get complicated. There are many moving parts :)
@sixbutton97 жыл бұрын
Humble Brag: Completed 1HR Tutorials: Go, Python, Java, Elixir, Erlang, C++, jQuery %50, Haskell %80 Tkinker: MessageBox, Calculator, started TextEditor Before matching video will compare results and add line numbers when watching. I couldn't figure that part out using the tkinker website. Four or Five of the Python ones. Patterns Observer, Sort and General working on Factory as I type. Completed means typed in everything myself and got to compile and run. I push pause and rewind like thousands of times while watching the videos. Setups Atom, PyCharm and Eclipse already was using Brackets for JavaScript. I have also expiremeted with NodeJS, Elm, JQuery, Bacon and Haskell, before watching your videos. The server side is my weakness. I did get the Django server to start. Looking forward to PyGame. Failures fSharp and Kivy. I can't get either of those to work on linux. General comment thanks for the free PHD. Thanks a bunch.
@derekbanas7 жыл бұрын
That's awesome! I'm glad you found them useful. Have you tried this for F# fsharp.org/use/linux/
@sixbutton97 жыл бұрын
Derek Banas Yeah, I tried everything I could google on the subject. I can open a FILE in Visual Studio Code and the F# code format coloring works. The little F# thingy shows up. I'm using the Ionide-fsharp extension. I can fsharp my .fs file and get a .exe using the terminal, but I can't get hello world to run. It always says file not found. I tried ./file name.exe etc.... Some things work really easy in Linux some don't.
@derekbanas11 жыл бұрын
You're very welcome :) I try to keep them interesting
@derekbanas11 жыл бұрын
You're very welcome :) I wish more people would make videos so that we could provide a free education for all.
@derekbanas11 жыл бұрын
I'm always happy to help :) Sorry about the confusion
@derekbanas11 жыл бұрын
Thank you very much :) I do the best I can to make complex ideas understandable. I'm glad you like them
@spicytuna086 жыл бұрын
From bottom of my heart, thank you for making this video. I really struggled understanding design patterns. Thanks
@derekbanas11 жыл бұрын
You're very welcome :) A C++ tutorial is in the works and will be out very soon
@abhineetrocks11 жыл бұрын
Love the way you breeze through it...never been on the edge of my seat watching a tutorial before...Thank you so much!!
@hbladeh6 жыл бұрын
How you break the "if else" into new line literally hurts... Nice video :D
@SujeetShenoy11 жыл бұрын
I understood factory pattern in just 10 minutes by watching this video...Thanks Derek ..You're awesome :-)
@derekbanas11 жыл бұрын
I can't think of any reason that that would hurt, but that doesn't necessarily mean you should use singleton. I have to think about that. Off of the top of my head I'd say don't do it just because it will make the code confusing
@benjaminmaclaren95485 жыл бұрын
This saved my degree, my last course I just couldn't get it, until I watched these videos. thanks
@derekbanas5 жыл бұрын
That's Awesome! I'm happy I could help
@derekbanas11 жыл бұрын
Thank you :) Sorry, but I don't think I used both in one tutorial. My refactoring tutorial does have a fair share of examples on how you can use patterns together.
@thecuriousone1210 жыл бұрын
Thank you so much Derek for these videos ! They are very helpful, I learn much more from you than from actually going to college!
@derekbanas10 жыл бұрын
UnspokenDesirexX I'm very happy that I can help :) You're very welcome.
@Sergio_Loureiro3 жыл бұрын
1.st time in decades someone made me actually like to look to Java code (me being more on the C#/C++ playing field).
@derekbanas11 жыл бұрын
In this tutorial I'm using a program named UmLet. It works on every OS
@darkthrongrising54706 жыл бұрын
Mr Banas, you have explained these patterns very well, I would venture yours was the best series on this topic. Good job and thank you sir!
@derekbanas6 жыл бұрын
Thank you :) I'm happy that it helped
@yougiely7 жыл бұрын
i learn from this list more than i learn at school four years.
@derekbanas7 жыл бұрын
Thank you :) I'm very happy that it helped
@Starface6069 жыл бұрын
seriously, I also read the design patterns book of those great four - but only after watching these videos I seem to understand the patterns:) good job!
@derekbanas9 жыл бұрын
+Starface606 Thank you :) My goal with these tutorials was to make the GOF book easier to understand.
@derekbanas11 жыл бұрын
You can change anything that you need. The design patterns are just guides. They don't have to follow exactly what I did
@sakules9 жыл бұрын
Why did you create EnemyShip newShip = null; in the factory class, when you never use them?
@filipghimpeteanu28809 жыл бұрын
Best explanation ever! You put the concepts very simple and straightforward! Thank you for the work you put in!
@derekbanas9 жыл бұрын
+Filip Ghimpeteanu You're very welcome :) I'm glad it helped
@derekbanas11 жыл бұрын
You're very welcome :) I'm glad I have an audience for these topics. You're english is very good by the way
@tomliuye11 жыл бұрын
although i use php, this video really helps me a lot about kowning factory design pattern, good job Derek
@bharathreddyappareddy31136 жыл бұрын
The main purpose of factory class is to hide object creation process. so in future if you want to add one more type that does not force you to alter the base code
@BobbitoDigital200711 жыл бұрын
Thanks for the quick reply, it turns out i had a } in the wrong place, again thanks so much for your time in these tutorials, they're great. Much appreciated.
@mrmohamedramadan64 жыл бұрын
best tutorial for this pattern, all the others are so confusing, got this in 2 minutes, thanks
@stevenfox96958 жыл бұрын
Your tutorials are great Derek. They're great for revisiting patterns and I always recommend you for reviewing or learn design patterns.
@derekbanas8 жыл бұрын
+Steven Fox Thank you very much :)
@derekbanas11 жыл бұрын
Thank you :) I have been think about covering Ruby because I don't think it would require a ton of videos to cover like java and c#. Ill try to add them soon to mix up the android series
@derekbanas11 жыл бұрын
Thank you very much :) I'm constantly trying to improve. Thanks for the input
@MsMaklaj8 жыл бұрын
Very clear and informative. Really like the way you jump right to the examples, which immediately show the usefulness of the pattern. Also, it's cool that you have an entire series dedicated to design patterns. Useful stuff. Thanks :)
@derekbanas8 жыл бұрын
+MsMaklaj Thank you very much :)
@91whoiswho11 жыл бұрын
really appreciate your effort. These videos are very clear and precise. I can start with these and then go for the detailed with a crisp and basic idea.Keep it up!
@derekbanas11 жыл бұрын
Thank you :) I do my best to make DP understandable. May God bless you and your family as well
@derekbanas11 жыл бұрын
William I don't know why I did that? I do these videos out of my head most of the time and at the time I must have been thinking about doing something with it. Feel free to delete it because it won't effect the program. Sorry about the confusion
@derekbanas11 жыл бұрын
I'm very happy that you've been able to use them with other languages! That's great
@derekbanas12 жыл бұрын
You're very welcome :) It makes me very happy to help
@masami28763 жыл бұрын
Even after 8 years still, a very good video with clear explains...Thanks!!!
@PatrickPitso6 жыл бұрын
You’re really good at this. It’s my first time seeing this in Java. I was taught in C++
@derekbanas6 жыл бұрын
Thank you :)
@abunism9 жыл бұрын
I don't find any other video explaining Design Patterns better.
@derekbanas9 жыл бұрын
+abunism Thank you :)
@F4TP6 жыл бұрын
In my opinion, the factory pattern offers multiple advantages… and he put in a fundamental part of the implementation of Factory Pattern before he needed to (the Abstract Class). If he had left this out at first and created multiple classes (individual enemy ship classes) without extending the abstract class, people would have understood that adding this (the abstract class) is a fundamental part of the pattern… in order to allow for runtime object instantiation (lazy instantiation)… which is obvious polymorphism (this is the real advantage of this pattern IMO). The second benefit then, would be that all of the ‘if-statements’ then are encapsulated in their own class (following the single responsibility’ design principle), aiding cohesion and reducing coupling. Please tell me that I am wrong so I get a better understanding of this pattern?
@parisanaderi16472 жыл бұрын
Thank you so much for your different example. I was read much of websites but I learned with you.
@prateekalmighty11 жыл бұрын
The way you are explaining in these videos, presentation are absolutely understanding and cool..:) Thanks muck Derek!!!!