Category: Conclusion

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 […]

Project – Building a search machine – Behavioral Patterns-1

Let’s start with a simple, classic example to demonstrate how the Template Method pattern works.Context: Depending on the collection, we want to use a different search algorithm. We want to use a binary search for sorted collections, but we want to use a linear search for unsorted collections.Let’s start with the consumer, a REST endpoint […]

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 […]

Implementing the Façade design pattern – Structural Patterns

The Façade pattern is a structural pattern that simplifies the access to a complex system. It is very similar to the Adapter pattern, but it creates a wall (a façade) between one or more subsystems. The big difference between the adapter and the façade is that instead of adapting an interface to another, the façade […]

Project – Greeter – Structural Patterns

Context: We’ve programmed a highly sophisticated greeting system that we want to reuse in a new program. However, its interface does not match the new design, and we cannot modify it because other systems use that greeting system.To fix this problem, we decided to apply the Adapter pattern. Here is the code of the external […]

Project – BookStore – Structural Patterns-3

In the preceding Create method, we create the corporation, add two stores, then return the result.The CreateTaleTowersStore and CreateEpicNexusStore methods create a store, set their name, address, and manager, and create three sections each: private IComponent CreateTaleTowersStore(){    var store = new Store(        “Tale Towers”,        “125 Enchantment Street, Storyville, SV 72845”,        “Malcolm Reynolds”    );    store.Add(CreateFantasySection());    store.Add(CreateAdventureSection());    […]

Project – BookStore – Structural Patterns-2

The BookComposite class implements the following shared features: Using the LINQ Sum() extension method in the children.Sum(child => child.Count()); expression allowed us to replace a more complex for loop and an accumulator variable. Adding the virtual modifier to the Type property allows sub-types to override the property in case their type’s name does not reflect […]

DecoratorB – Structural Patterns-2

In the preceding code, we registered ComponentA as the implementation of IComponent, with a singleton lifetime, just like the first time.Then, by using Scrutor, we told the IoC container to override that first binding and to decorate the already registered IComponent (ComponentA) with an instance of DecoratorA instead. Then, we overrode the second binding by […]



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