Software Developer
Pipeline Architecture (also called Pipes and Filters) is a design pattern where data flows through a series of processing units, called filters, connected by pipelines. Each filter performs a transformation on the input and passes the result to the next stage.
Component | Responsibility |
---|---|
Source | Generates or provides input data |
Filters | Process, transform, or modify data |
Pipelines | Connect filters and handle data flow |
Sink | Collects or stores the processed output |
using System;
using System.Collections.Generic;
using System.Linq;
public interface IFilter<T>
{
T Process(T input);
}
public class UpperCaseFilter : IFilter<string>
{
public string Process(string input) => input.ToUpper();
}
public class ReverseFilter : IFilter<string>
{
public string Process(string input) => new string(input.Reverse().ToArray());
}
public class Pipeline<T>
{
private readonly List<IFilter<T>> _filters = new();
public Pipeline<T> AddFilter(IFilter<T> filter)
{
_filters.Add(filter);
return this;
}
public T Process(T input)
{
return _filters.Aggregate(input, (current, filter) => filter.Process(current));
}
}
class Program
{
static void Main()
{
var pipeline = new Pipeline<string>()
.AddFilter(new UpperCaseFilter())
.AddFilter(new ReverseFilter());
string result = pipeline.Process("hello world");
Console.WriteLine(result); // Output: DLROW OLLEH
}
}
Pipeline Architecture is ideal for data processing, image transformation, and stream-based applications. Its modular design improves maintainability and scalability, making it a powerful architectural choice.
Related Articles
Navigating the Intersection of Business and Technology
Essential tips for avoiding common pitfalls in application development