Fluent Builder Design Pattern04:33

  • 0
Published on November 19, 2017

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

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

Slides

Design Patterns Tutorial playlist

Design Patterns Text articles and slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

https://cafeadobro.ro/

https://www.stagebox.uk/wp-includes/depo10-bonus10/

https://iavec.com.br/

Enjoyed this video?
"No Thanks. Please Close This Box!"