Master the Builder Pattern: The King of Creational Design Patterns in C# | ASP.NET Core Tutorial

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024

Комментарии • 48

  • @thehuggz-i9k
    @thehuggz-i9k 4 месяца назад +2

    Programming magic is one of the reasons I LOVE this field. It's a beautiful thing when a library or piece of software works in a magical way and makes the other developers think about how it was achieved. Puzzles everywhere!

  • @kristianaranda
    @kristianaranda Год назад +7

    It is amazing how, by using the right patterns and techniques, we can hide the complexity of the domain and show only the "intention revealing expression" (I loved this sentence) to the consumer. Thanks for sharing!

  • @paultumbaco5300
    @paultumbaco5300 Год назад +7

    I have to say this pattern was one of the most complex for me to understand and I'm still struggling in knowing when and how to develop it in my own in the correct way. This a good example,complex though.. thanks for sharing

  • @danielnababan1414
    @danielnababan1414 Год назад +3

    Great Lesson! I always learn something new with all your video sir. Thanks.

  • @tranthanhphong91
    @tranthanhphong91 Год назад +1

    This is a good demonstration for me to understand Builder Pattern. Great lesson! Thank you for making that!

  • @payman5581
    @payman5581 Год назад +1

    Keep up the good work. Very nice explanation with real world example.

  • @thegaribovv
    @thegaribovv Год назад +1

    Thank you Zoran for such good , real-world example

  • @sunnypatel1045
    @sunnypatel1045 Год назад +1

    Excellent I would like to see how you do your strategy pattern and adapter pattern

    • @zoran-horvat
      @zoran-horvat  Год назад +4

      I do have plans to demonstrate Strategies in one of the future videos.

  • @abdullahishuru
    @abdullahishuru Год назад +1

    This is great content. Can we have the link to the full course showing how all the implemetations of the BOOK STORE app.

    • @zoran-horvat
      @zoran-horvat  Год назад

      There is no full course at the moment. I might make it in the near future, though.

    • @abdullahishuru
      @abdullahishuru Год назад

      @@zoran-horvat will be on the lookout then... ☺️

  • @vamvdotnet
    @vamvdotnet Год назад

    Excellent video! And yes, this is a very complex example. It fits really great for scenarios like this one.

    • @zoran-horvat
      @zoran-horvat  Год назад +3

      If I came up with a simpler example, then there would possibly be no justification to apply the Builder in the first place. I might also make a video that demonstrates how exactly it comes that we don't need a Builder in simpler cases.

    • @vamvdotnet
      @vamvdotnet Год назад +1

      I understand. I'd be more than happy to see another video with simpler alternatives, but take your time :). Thank you!

    • @mehdi_aghaei_
      @mehdi_aghaei_ Год назад +1

      Great use case of builder with proxy methods, Before I just used it to create test data for complex objects , now I have some new insights😊

  • @seriyezh
    @seriyezh Год назад

    Thank you for the great video! What if we need to guide the users of the builder on which method they can use next? For instance if builder has mandatory steps or one steps can be called only after others? I guess we can introduce different interfaces and return them after each operation. Maybe you can share what could be the better way of implementing such complex builder?

    • @zoran-horvat
      @zoran-horvat  Год назад +1

      That is a good question, indeed! You may try this article I wrote a few years ago: codinghelmet.com/articles/advances-in-applying-the-builder-design-pattern
      Not everything in that article would I back today, but it should be about the topic you have mentioned here.

    • @seriyezh
      @seriyezh Год назад +1

      Thank you so much!

  • @vatreni8088
    @vatreni8088 Год назад

    Seems the builder is capturing domain concepts that belong to the invoice. The invoice itself is anaemic. How about capturing rules in the model itself and then a printer decoration object knows how to produce the output. Thoughts?

    • @zoran-horvat
      @zoran-horvat  Год назад +1

      There is no problem in having domain rules in the builder if the builder is named after the domain it is building. Its whole purpose is to relieve the domain model from complex construction logic.
      It is true that the domain model has remained empty (not anemic yet) after the change, but that is only because this is the demo code. I didn't implement any behavior of the invoices other than their construction and UI. You can imagine further requirements being implemented right in the invoices, and then you would appreciate them not being inflated with the construction logic.

  • @superpcstation
    @superpcstation Год назад

    Hi Zoran, I've noticed that Pluralsight have marked some of your Tactical Design Patterns courses and your "Making Your C# 6 Code More Object-oriented" course as retired. Would you still recommend watching these courses to somebody who have not gone through these before?

    • @zoran-horvat
      @zoran-horvat  Год назад +1

      I still recommend those courses until I publish a new version. The problem with older courses is in the use of obsolete syntax, but on the positive side the themes gave not changed, and the way we address the problems is still the same.

    • @superpcstation
      @superpcstation Год назад

      @@zoran-horvat Thanks, i will check these out :)

  • @coolfyb
    @coolfyb Год назад +1

    Excellent ❤

  • @nalinsharma9881
    @nalinsharma9881 Год назад

    @zoran-horvat Isn't this just a "Fluent Interface" implementation and not actual Builder pattern?

    • @zoran-horvat
      @zoran-horvat  Год назад

      It is actually a fluent builder, like StringBuilder, for example.

  • @rakeshkumarreddymudda
    @rakeshkumarreddymudda Год назад

    Is it good practice to use business logic in builder method? While unit testing the calculations will it not become diffcult?

    • @zoran-horvat
      @zoran-horvat  Год назад

      This is a very specific builder - it is part of the domain model and it naturally contains domain logic.
      However, if more requirements came, asking for variation, then the Builder would probably have to receive appropriate strategies or something of that sort.

  • @kenbrady119
    @kenbrady119 2 месяца назад +1

    I am learning from your fluidity with LINQ and your skill in highlighting best use of design patterns. I started writing software in the 80-90's in pursuit of scientific knowledge. That is my only turn-off about your presentations - they represent capitalism, with "customer's requirements" and the need to profit. I may be idealistic, but I would love to see examples from the scientific domain, where the code more often needs to discern patterns, not apply policies.

  • @SteveNgaiCheeWeng
    @SteveNgaiCheeWeng Год назад

    Can we create an automated unit test for this builder class?

    • @zoran-horvat
      @zoran-horvat  Год назад

      Yes, of course. It would test all invariants and postconditions from the specification of requests. Since none of the requirements has any variation, there is nothing to inject into the Builder, which makes testing easier.

  • @DevMeloy
    @DevMeloy Год назад

    I've used the builder method a couple times in the past, but instead of returning "this" I would return an Interface with the appropriate "next" steps exposed.

    • @zoran-horvat
      @zoran-horvat  Год назад

      That is the fluent builder design. It is useful in cases when an unrestricted use of the builder could cause confusion and errors.

    • @DevMeloy
      @DevMeloy Год назад +1

      @@zoran-horvat Thanks! Great video's by the way.

  • @m5s10
    @m5s10 Год назад

    This is a great example for encapsulating the extremely complex logic to make life easier for a caller. I have a question for this solution though. How would you unit test this? For example, AppendFee, AppendInterest and GetInterest for are complex enough on their own to have unit tests for each of them separately. But since they're private, you can't reach them from the tests (unless you make them internal and make internals visible in test project or public, but that brings up some red flags in design, so I don't think it's a good approach). You can test the builder as a whole, but since you call AppendFee(AppendInterest(deliquency)) in Build method, it would not really be trivial to know why some test failed - is it the fee calculation that's wrong or interest calculation? Or maybe both? Or maybe neither? Thanks in advance.

    • @zoran-horvat
      @zoran-horvat  Год назад +1

      I would focus testing on the attributes of the product.
      Builder normally has more than one responsibility, if we assume that each component it manages is a separate responsibility. Each component naturally requires unit testing, and so I envision it would be useful to focus on one component per test and keep all the rest at bare minimum. Then assert the qualities, the consequences caused by that component in the product.
      I think that adding variation to the builder for the sake of testing would be overengineering. The whole purpose of the builder is to be the single point where the rules of composition are defined, so leave it be that way, that is my opinion.

    • @m5s10
      @m5s10 Год назад

      @@zoran-horvat So, if I understood correctly, in the example of AppendFee(AppendInterest(deliquency)), you'd construct an object via the builder in which the AppendInterest(deliquency) would not change the deliquency at all (or as little as possible), but in that object there's a significant change done by AppendFee method for the result of previous operation and test the result? And another test would be vice versa - interest would "change the result a lot", while fee would make minimal or no difference to the final result?

    • @zoran-horvat
      @zoran-horvat  Год назад +1

      @@m5s10 You can skip any method that is not mandatory and use simplest possible arguments in those that must be called. Then carefully call the method you are interested in, and assert that the result of that call has caused the expected change in the product.

    • @m5s10
      @m5s10 Год назад

      @@zoran-horvat understood, thank you

  • @Pasukaru0
    @Pasukaru0 Год назад +1

    Are you spying on me? I just used this pattern today.

  • @manmohanmundhraa3087
    @manmohanmundhraa3087 28 дней назад

    Is not class is too big ?

    • @zoran-horvat
      @zoran-horvat  28 дней назад

      @@manmohanmundhraa3087 You can rarely choose the size of the builder class. It is doing one task - to build a product object in a series of steps - and it does it all.
      It is not uncommon to see builders that are a thousand lines long and yet quite easy to develop and even easier to use.
      It is funny to see how many common rules of OOD do not hold when we talk about builders.