Categories: Design Pattern

Behavioral Patterns – Iterator

#2 Web Application Project

This sample will show the interface class method’s iterator pattern sample in the web application situation because the interface class methods will be a little challenging to edit when the developers/readers write this pattern code in the web application. The abstract class methods are more straightforward than the interface class methods when the developers/readers write this pattern code, but the abstract class running mechanism will be more complicated than the interface class works.

Step 1: Create three interface class files in the Core projects. One interface class file name sets “IIterator.” Another interface class file name sets “IIteratorAggregate.” Other interface class file name sets “IIteratorServices.”

Fig 1 Solution explorer – Interface class files
Fig 2 IIterator interface class source code
Fig 3 IIteratorAggregate interface class source code
Fig 4 IIteratorServices interface class source code

Step 2: Create the Iterator pattern’s BLL layer class files in the Core projects. One class file name sets “ItemCollection,” which function is about collecting every one node data. Another class file name sets “AlphabeticalOrderIterator,” which is about everyone’s data order.

The “ItemCollection” class file inherits the IIteratorAggregate interface class files and adds the IDisposable interface class. The “AlphabeticalOrderIterator” class file inherits the IIterator interface class files and adds the IDisposable interface class. Every one operation should add the dispose function operation in every one function.

Fig 5 ItemCollection class file source code
Fig 6 AlphabeticalOrderIterator class file source code

Step 3: Create the iterator pattern service class files in the Core project, which file name sets “IteratorServices” and inherits the “IIteratorServices” interface class files. Suppose the data has been accessed before executing the iterator pattern operations, then the generic type repository’s GetAll function result assigns to “itemCollection” variables.

Fig 7 IteratorServices class file source code

Step 4: Add the iterator pattern-related files in the web project, such as view flies, controller files. Register the iterator pattern files in the web project’s start.cs file.

services.AddScoped(typeof(IIteratorServices<>), typeof(IteratorServices<>));
Fig 8 Iterator pattern executing result

Reference

Page: 1 2

davidsky69

View Comments

Recent Posts

SOLID Principles – Single-responsibility principle

The single-responsibility principle (SRP) is a computer-programming principle that states that every module, class or…

4 years ago

Microservices – Command and Query Responsibility Segregation(CQRS)

Command query responsibility segregation (CQRS) generalizes CQS to message-driven and event-driven architectures: it applies the CQS…

4 years ago

Microservices – Domain-driven design(DDD)

Domain-driven design (DDD) is a software design approach focusing on modelling software to match a…

4 years ago

Microservices – Onion architecture

A microservice architecture – a variant of the service-oriented architecture (SOA) structural style – arranges…

4 years ago

Unit Of Work pattern concepts in .NET

The Repository pattern and Unit of Work pattern are used together in most time. Unit…

4 years ago

Behavioral Patterns – Visitor

Visitor – It allows the program changes the algorithm and the operations that base on the visitor…

4 years ago