Category: Flexibility in action

Project – Improved message interpreter – Behavioral Patterns

Conclusion The Chain of Responsibility pattern is another great GoF pattern. It divides a large problem into smaller, cohesive units, each doing one job: handling its specific request(s).Now, let’s see how the Chain of Responsibility pattern can help us follow the SOLID principles: Next, let’s use the Template Method and Chain of Responsibility patterns to […]

Design – Behavioral Patterns-2

Each handler does two things: Let’s use Program.cs as the consumer of the Chain of Responsibility (the Client) and use a POST requests to interface with our REST API and build the message.Here is the first part of our REST API: var builder = WebApplication.CreateBuilder(args);builder.Services.AddSingleton<IMessageHandler>(    new AlarmTriggeredHandler(        new AlarmPausedHandler(            new AlarmStoppedHandler()))); In the preceding code, […]

Design – Behavioral Patterns-1

The most basic Chain of Responsibility starts by defining an interface that handles a request (IHandler). Then we add classes that handle one or more scenarios (Handler1 and Handler2):  Figure 12.2: Class diagram representing the Chain of Responsibility pattern  A difference between the Chain of Responsibility pattern and many other patterns is that no central […]

Implementing the Template Method pattern – Behavioral Patterns

Before you begin: Join our book community on Discord Give your feedback straight to the author himself and chat to other early readers on our Discord server (find the “architecting-aspnet-core-apps-3e” channel under EARLY ACCESS SUBSCRIPTION). https://packt.link/EarlyAccess This chapter explores two new design patterns from the well-known Gang of Four (GoF). They are behavioral patterns, meaning […]

Conclusion – Structural Patterns

The Façade pattern is handy for simplifying consumers’ lives, allowing us to hide subsystems’ implementation details behind a wall. There are multiple flavors to it; the two most prominent ones are: Now, let’s see how the transparent façade pattern can help us follow the SOLID principles: Finally, let’s see how the opaque façade pattern can […]

Flexibility in action – Structural Patterns

As discussed, the transparent façade adds more flexibility. Here, we explore this flexibility in action.Context: We want to change the behavior of the TransparentFacade class. At the moment, the result of the transparent/b endpoint looks like this: Component B, Operation CComponent B, Operation DComponent C, Operation F To demonstrate we can extend and change the […]

The program – Structural Patterns

Now, let’s analyze the consumer, an ASP.NET Core application that forwards HTTP requests to the façades and return the result as their response.The first step is to register the dependencies like this: var builder = WebApplication.CreateBuilder(args);builder.Services    .AddOpaqueFacadeSubSystem()    .AddTransparentFacadeSubSystem(); With these extension methods, the application root is so clean that it is hard to know that […]

Transparent façade – Structural Patterns

The transparent façade is the most flexible type of façade and is exceptionally suitable for a system that leverages dependency injection. The implementation is similar to the opaque façade, but the public visibility modifier changes how consumers can access the class library elements. For this system, it was worth adding interfaces to allow the consumers […]

Conclusion – Structural Patterns

The Composite pattern effectively builds, manages, and maintains complex non-linear data structures. Its power is primarily in its self-management capabilities. Each node, component, or composite is responsible for its own logic, leaving little to no work for the composite’s consumers. Of course, a more complex scenario would have led to a more complex interface.Using the […]

Project – BookStore – Structural Patterns-1

Context: We built a program in the past to support a bookstore. However, the store is going so well that our little program is not enough anymore. Our fictional company now owns multiple stores. They want to divide those stores into sections and manage book sets and single books. After a few minutes of gathering […]



          Copyright © 2015-2024 | About | Terms of Service | Privacy Policy