Photo by Flo P on Unsplash
Originally posted on my site
Hey folks! few weeks ago i started a new challenge to learn about one design pattern ev...
For further actions, you may consider blocking this person and/or reporting abuse
I'm trying to write a library for scaffolding test files for JS, and I think this post is really going to help a lot in that! Thanks for posting!
Great! Happy to help. :D
Yeah man - I forked the repo and ran my tool keurig
against the creational folder and found some things I needed to change!
I started to study design patters yesterday, and in the beging I tought it is a little bit complicated. Your article really make it more easier to understand, the code examples realy helped me! Thanks!
Wow nice to hear that. I'm glad it helped you. 😊
Btw if you want you can also take the #DesignPatternsEveryday challenge.
twitter.com/hashtag/DesignPatterns...
Holy God! This needs to be an ebook!
hehe, Thank you but i learned from these sources and i think these two books deserves some kudos!
refactoring.guru/design-patterns/
sourcemaking.com/
Nice Article Anurag. I need to refresh my knowledge in patterns so I will read one per day (and leave my comments, I hope that is ok!)
Day 1:Abstract Factory Pattern:
It would be good to have a summary before the ending. The most important thing to mention here:
"The benefit of this pattern is that no matter which family/factory your
guiFactory
instance is, you will ALWAYS implement using this code:createButton(); and button.render());
This is where the flexibility of pattern comes in."
Day 2: Builder pattern
Missing the final step:
_"When you have finished building your object, you should call build() to instantiate:
let myTruck = truck.build();
"let mySedan = sedan.build();
Day 4: Singleton
You can also implement a lazy initialization singleton. Same concept, but singleton instantiation it's delayed until the object is required. This can improve performance in some cases.
class LazySingleton {
name = "Im a LazySingleton";
static instance;
static getInstance() {
if(!instance){
this.instance = new LazySingleton();
}
return instance;
}
}
// instance does not exist yet
instance2 = LazySingleton.getInstance();
// instance was just created
console.log(instance.name);
@jmojico Opps yup! didn't noticed it the .build() part, fixed it.
Great. Thanks for the feedback Julian. 😊
Hi again Anurag!
I'm still reading your article, day by day :)
Regarding the adapter pattern:
In this line: Does the method
LoggerAdapter.log()
needs type argument ?Would it be better if it takes it from
this.type
?Thank you!
Actually i have seen some example where the type argument isn't required. And some of them used the type argument it depends on the context I think.
I think I have to update that example with better one.
Here's another example if you wanna look:github.com/anuraghazra/design-patt...
// more info
refactoring.guru/design-patterns/a...
Very nice and exhaustive article! In my experience, I've seen people misuse a lot of these patterns. How would you tell if for example the strategy pattern is not a good choice for your problem? Would be great if you could expand on that in your article.
It's already mentioned in the post
Design patterns are not silver bullet to every problem and if anyone is creating the problem just to solve it with a specific design pattern then it's very harmful.
IMO any solution should be rapidly prototyped first and then and only then if it's beneficial to implement a design pattern (or combination of them) we should approach for it.
Really nice article. Your examples are cool.
I think it would have beena better read if they were broken into smaller articles but I learnt a lot from it
Guruji awesome.
Thanks for sharing this. One of the best posts I have come across in dev.to.keep writing 😃😃😃
Thank you arjun.. i'm glad you liked it.
You thought wrong, sir, I read it all and even took some notes on the patterns i didn't know!
Thanks for the article!
Haha 😄 thanks for reading!
So great to see theoretical concepts which are usually hard to grasp made simple with examples and menmonics based on real life, thanks a lot for this article!
Thanks! I'm glad to that you liked it.
Nice work!! I was looking for this
Thanks! I'm glad you found it helpful