https://github.com/mreshboboyev/fluent-builder-design-pattern
A C# repository demonstrating the Fluent Builder design pattern, highlighting its advantages and differences compared to the traditional builder approach for creating complex objects.
https://github.com/mreshboboyev/fluent-builder-design-pattern
asp-net-core best-practices builder-pattern c-sharp clean-code design-pattern fluent-builder-design-pattern object-creation oop software-design web-api
Last synced: 8 months ago
JSON representation
A C# repository demonstrating the Fluent Builder design pattern, highlighting its advantages and differences compared to the traditional builder approach for creating complex objects.
- Host: GitHub
- URL: https://github.com/mreshboboyev/fluent-builder-design-pattern
- Owner: MrEshboboyev
- Created: 2025-01-02T06:05:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-27T11:14:32.000Z (over 1 year ago)
- Last Synced: 2025-10-10T13:07:53.631Z (8 months ago)
- Topics: asp-net-core, best-practices, builder-pattern, c-sharp, clean-code, design-pattern, fluent-builder-design-pattern, object-creation, oop, software-design, web-api
- Language: C#
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fluent Builder Design Pattern in C#
This repository demonstrates the **Fluent Builder Design Pattern** in C#, showcasing how it differs from the traditional builder approach for creating complex objects. By using this pattern, developers can write cleaner, more readable, and more maintainable code for object construction.
## π What is the Fluent Builder Pattern?
The Fluent Builder pattern is an advanced implementation of the Builder Design Pattern. It leverages **method chaining** to create objects step by step, allowing for a more readable and intuitive API. This approach is especially useful for constructing objects with numerous properties or configurations.
### π Fluent Builder vs. Traditional Builder
| Feature | Traditional Builder | Fluent Builder |
|-------------------------|----------------------------------|--------------------------------|
| **Readability** | Step-by-step, more verbose | Chainable, concise, intuitive |
| **Ease of Use** | Requires intermediate objects | Streamlined with method chaining |
| **Flexibility** | Moderate customization | Highly customizable with clean syntax |
## π Repository Structure
The repository contains:
- **Examples of the traditional builder pattern**: Demonstrating the step-by-step approach.
- **Examples of the fluent builder pattern**: Showcasing method chaining for a cleaner API.
## π Usage Guide
### Step 1: Clone the Repository
```bash
git clone https://github.com/MrEshboboyev/fluent-builder-design-pattern.git
cd fluent-builder-design-pattern
```
Step 2: Open the Project
Open the project in your favorite C# IDE (e.g., Visual Studio).
Step 3: Run the Examples
Run the provided examples to see the differences between traditional and fluent builder patterns.
π Code Example
Hereβs a quick comparison:
Without Builder :
```bash
var test = new Test
{
Id = Guid.NewGuid(),
TestName = createTestRequest.TestName,
Description = createTestRequest.Description,
StartDate = createTestRequest.StartDate,
EndDate = createTestRequest.EndDate,
IsActive = createTestRequest.IsActive,
Tags = createTestRequest.Tags,
Difficulty = createTestRequest.Difficulty,
MaxParticipants = createTestRequest.MaxParticipants,
Sections = createTestRequest.Sections.Select(s => new TestSection
{
Title = s.Title,
TimeLimit = s.TimeLimit,
QuestionCount = s.QuestionCount
}).ToList()
};
```
With Builder :
```bash
var test = new TestBuilder()
.WithBasicInfo(
createTestRequest.TestName,
createTestRequest.Description,
createTestRequest.StartDate,
createTestRequest.EndDate)
.WithIsActive(createTestRequest.IsActive)
.WithTags(createTestRequest.Tags)
.WithDifficulty(createTestRequest.Difficulty)
.WithMaxParticipants(createTestRequest.MaxParticipants)
.WithSections(createTestRequest.Sections)
.Build();
```
π Benefits of the Fluent Builder Pattern
Improved Readability: Code is easier to understand with method chaining.
Clean API: Reduces clutter and complexity in object creation.
Extensibility: Easily extendable for future requirements.
π About the Author
This repository was created by MrEshboboyev, showcasing modern design patterns and best practices in software development.
π License
This project is licensed under the MIT License. Feel free to use and adapt the code in your own projects.
π Tags
C#, Fluent Builder, Design Patterns, Builder Pattern, Object Creation, Clean Code, OOP, Best Practices
Feel free to customize this further based on your specific needs or add additional examples. Let me know if youβd like to refine or expand any section! π