Builder Pattern Example in C#

Ғылым және технология

In the first episode of Five Minute Fridays, I very quickly explore the wonderful, sometimes-useful, sometimes-over-complicated Builder Pattern. I talk briefly about two different implementations of the Builder Pattern in C#, as you might apply it to a purchase order builder for an imaginary bakery.
Check out www.productivedev.com for my latest premium course on ASP.NET Core 2.0, where we build a Forum App from scratch and deploy it to Azure. Use coupon code 'thankyou' to get 35% off when purchasing a Pro Membership!
The Builder Pattern helps separate the construction of an object from its representation. I've found the Fluent Builder Pattern to be quite useful when creating some data for building automated tests.
Sorry this one goes over 5 minutes, I promise to get the time down in future episodes.
If you have any questions or requests for future episodes, leave them in the comments below!
Intro music by taketime - taketime.bandcamp.com & / taketimetaketime
Used with permission. Go check out his great music!
GitHub repo with code from this video:
github.com/wesdoyle/5-minute-...

Пікірлер: 43

  • @rogerr4469
    @rogerr44694 ай бұрын

    Nice nice. I like the fluent builder example, it really makes it easy for developers to understand someone else's code.

  • @flockomotion
    @flockomotion2 жыл бұрын

    "Clean code should read like prose." - your fluent builder really expresses this ideal!

  • @Hardtakk
    @Hardtakk4 жыл бұрын

    Thank you so much! I suddenly got a Builder Pattern at me in a project without ever having seen one before and this really helped me understand the basic idea.

  • @abhijeetsingh1939
    @abhijeetsingh19396 жыл бұрын

    Great tutorial Wes! Keep more coming! Namaste from India!

  • @Mhblabla
    @Mhblabla5 жыл бұрын

    How does this compare versus the fluent methods being on the class we are producing itself? For instance like in the accepted answer in this SO question: stackoverflow.com/questions/1794848/writing-my-first-dsl-in-c-sharp-and-getting-hung-up-on-funct-action The issue I have with the described way of doing things in this video is that you end up with duplicate code in the builder and in the class the builder is producing (for example, all of the properties are being repeated in the builder class (albeit being replaced with fields).

  • @dgodiegomartins
    @dgodiegomartins3 жыл бұрын

    Great content. One question. Why are you returning the FluentPOBuilder instead return the interface IPurchaseOrderBuilder ?

  • @kevinmarkandrada
    @kevinmarkandrada6 жыл бұрын

    SOLID Principles + Enterprise Architecture + MVC Pattern + .NET Core + Web API + Vue.js + C# in One Project PLEASE! From Philippines! Nice Vlogs and Tutorials! God bless

  • @bravoelliot
    @bravoelliot6 жыл бұрын

    Excellent video

  • @lyalin
    @lyalin5 жыл бұрын

    Great video!

  • @mrdiv8418
    @mrdiv84186 жыл бұрын

    Thank you! This 5FRI format is great. Concise and informative. I would love to see more videos regarding Gang of Four Design Patterns. May be even separate playlist or series. This topic is very confusing for newbies like I'm myself.

  • @WesDoyle

    @WesDoyle

    6 жыл бұрын

    Thanks, Greg - I'll definitely have to put that together!

  • @mrclaytron
    @mrclaytron6 жыл бұрын

    Nice one Wes!

  • @jemmett8885
    @jemmett88855 жыл бұрын

    Is that a theme making his font colour and style that way?

  • @inkofthedragon
    @inkofthedragon Жыл бұрын

    Do you think the Builder Pattern could be an effective way to build different kinds of AiControllers with different behaviours/states and abilities, say for an Orc, Goblin, Troll, etc? Thanks

  • @mozamilahmadafghan4889
    @mozamilahmadafghan4889 Жыл бұрын

    The link for the Github Code is dead.

  • @Ohlawdie
    @Ohlawdie6 жыл бұрын

    Hey Wes, I couldn't help but notice the color settings for your code! How'd you get your '=" sign to be red?

  • @WesDoyle

    @WesDoyle

    6 жыл бұрын

    Hey Evan, thanks for the message. Tools > Options > Fonts and Colors > Operator, I believe. My vssettings file is available on my GitHub!

  • @Ohlawdie

    @Ohlawdie

    6 жыл бұрын

    Awesome, thanks!

  • @Over9000Nine
    @Over9000Nine4 жыл бұрын

    Hey man, thank you for your video, great explanation. I have one question: What if, for one bread supplies PO you do not want to add Requested By. In your current implementation the director class always calls builder.AddRequestedBy(). What is the best way to manage such a case? I know my question is kinda late but I hope you see it. Thanks!

  • @WesDoyle

    @WesDoyle

    4 жыл бұрын

    Good question. This so-called "Director" class provides an additional layer of abstraction for us to define ways of constructing our order. So, if you wanted to execute a different chain of events, you could create a separate method to do that in the same class, like ConstructForX. Just an idea, haven't thought about it much!

  • @Over9000Nine

    @Over9000Nine

    4 жыл бұрын

    @@WesDoyle Thank you :)

  • @rockingdude8383
    @rockingdude83834 жыл бұрын

    github repo is broken link

  • @refreshious
    @refreshious6 жыл бұрын

    You going to go through all the GoF patterns?

  • @WesDoyle

    @WesDoyle

    6 жыл бұрын

    +Kinman Li perhaps eventually. That would be an interesting project.

  • @luistc1721
    @luistc17216 жыл бұрын

    what style do you use for visual studio ?

  • @WesDoyle

    @WesDoyle

    6 жыл бұрын

    +Luis TC check out my dotfiles on my github, I've exported my vs settings. github.com/wesdoyle

  • @luistc1721

    @luistc1721

    6 жыл бұрын

    Wes Doyle thanks .. excellent tutorial

  • @luistc1721

    @luistc1721

    6 жыл бұрын

    Wes Doyle Greetings from Peru

  • @WesDoyle

    @WesDoyle

    6 жыл бұрын

    Thanks for watching! All the best to you!

  • @nesekaramanler914

    @nesekaramanler914

    5 жыл бұрын

    @@WesDoyle style ok but font is different :(

  • @augis1393
    @augis13936 жыл бұрын

    Hey Wes, what do you think how many languages does developer needs to know these days? It seems like you are familiar with quite a few. Cheers for great tutorials!!!

  • @WesDoyle

    @WesDoyle

    6 жыл бұрын

    Hi Augustinas - I believe it really depends on your goal. As a default answer, in terms of coding for employment, I would say that it's 'good enough' to be proficient with a single popular language. It's perhaps more important to know how to get things done in your area of interest - and from there, learning about best practices in software development more generally. That said, I find it enjoyable to explore different languages and paradigms. One of the great things about learning one language well is that it helps you pick up concepts in subsequent languages more quickly. I think it's a great idea to pick a second or third language that works completely differently than the language you're most proficient with - for example, if you use Java regularly, explore Haskell. If you use Javascript, take Go for a spin, etc.

  • @augis1393

    @augis1393

    6 жыл бұрын

    Thank you for a great answer!

  • @dotnet-azure
    @dotnet-azure2 жыл бұрын

    github repo doesn't work

  • @TheAceInfinity
    @TheAceInfinity6 жыл бұрын

    Builder pattern and factory are both very useful.

  • @WesDoyle

    @WesDoyle

    6 жыл бұрын

    Definitely!

  • @hovadopekelne
    @hovadopekelne5 жыл бұрын

    ... silverface, good choice ...

  • @soccerfinatic234
    @soccerfinatic234 Жыл бұрын

    github doesnt work for this :(

  • @OghamTheBold
    @OghamTheBold5 жыл бұрын

    *I.O.U* ( Implicit Operator _Useful_ )

  • @rahmatabadi3839
    @rahmatabadi38395 жыл бұрын

    Your example is too complicated so it will take unnecessary time to decipher your scenario. It will be better to choose a simple scenario so we don't need to decipher unnecessary parts. Reduces the number of properties as minimal as possible and use simple method names as well.

  • @ferreiradev

    @ferreiradev

    5 жыл бұрын

    For easy scenarios, check out the Head First Design Patterns. It is rare to find well implemented demonstrations for complex usage of Builder patttern

Келесі