Fluent Builder Design Pattern

Published: 23 October 2017
on channel: kudvenkat
34,821
172

In this video we will discuss and implement
1. Fluent Interface
2. Enhance the Builder Implementation with Fluent Implementation
3. Builder vs Abstract Factory/Factory

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

Business Requirement : Provide an option to choose and build configuration of the system which is allocated to the employees. The configuration options that user can choose are RAM, HDD, USB Mouse etc. Choose the system configurations based on the computer type that we need to build. For example, A laptop users can choose touch screen and the desktop users can configure keyboard and mouse.

Fluent Interface : The idea behind a fluent interface is that one can apply multiple properties to an object by connecting them with dots and without having to re-specify the object each time

C# uses fluent programming extensively in LINQ to build queries using the standard query operators. The implementation is based on extension methods

Fluent Interface Features : Fluent interface is a method for constructing object oriented APIs, where the readability of the source code is close to that of ordinary written prose

Fluent interface is normally implemented by using method cascading (concretely method chaining)

Fluent code is much more readable and allows to vary a product’s internal representation

Fluent Encapsulates code for construction and representation and Provides control over steps of an object construction process

Searching, Sorting, pagination, grouping with a blend of LINQ are some of the real world usage of fluent interface in combination with builder design pattern.

However, it’s not mandatory to implement fluent interfaces with builder design pattern however, the idea of this session is explore and integrate the fluent interface with builder design pattern.

Fluent Builder Implementation

Step 1 : Change the ISystemBuilder Interface methods to return ISystemBuilder

Step 2 : Implement the ISystemBuilder Interface methods in Laptop and Desktop Builder Classes

By returning the ISystemBuilder and by using this as the return statement we are indicating that after assigning the properties of the desktop or laptop we are returning back the same ISystemBuilder to allow the method chaining.

Step 3 : Enhance the Configuration builder with Fluent Implementation

Step 4 : Run the application and build the system. Notice that depending on the system type the respective system configurations are built using Fluent Builder implementation.

Builder Vs Factory and Abstract Factory

Builder design pattern encapsulates complex creation into a single method.

Builder design pattern focuses on construction of object in a step by step manner whereas Abstract factory pattern is used to solve problems related to the creation of families of products.

Builder design pattern returns the object after step by step construction of the complex object where as in Abstract factory or Factory pattern, we return the created product immediately.

To conclude, many application designs start out using Factory which is less complex and evolve towards Abstract Factory and Builder as the complexity increases with a demand of flexibility.

In the next video we will discuss Prototype design pattern.

Text version of the video
http://csharp-video-tutorials.blogspo...

Slides
http://csharp-video-tutorials.blogspo...

Design Patterns Tutorial playlist
   • Introduction to Design Patterns  

Design Patterns Text articles and slides
http://csharp-video-tutorials.blogspo...

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...

All Dot Net and SQL Server Tutorials in Arabic
   / kudvenkatarabic  


On this page of the site you can watch the video online Fluent Builder Design Pattern with a duration of hours minute second in good quality, which was uploaded by the user kudvenkat 23 October 2017, share the link with friends and acquaintances, this video has already been watched 34,821 times on youtube and it was liked by 172 viewers. Enjoy your viewing!