Skip to main content

3 posts tagged with "visitor-pattern"

View All Tags

Implementing APIs with the visitor pattern

· 4 min read

I want to leverage my visitor pattern source generator to implement a simple minimal api.

I aim to:

  • Have a request and a request handler for my endpoint. I will not use mediatr or any similar library and I will not use any real storage, only some in memory data structure to showcase the visitor pattern approach.
  • The request handler Handle method returns an interface, every subtype represents a different type of result, a success, and one type for each error (provided) emitted by the handled.
  • For each subtype we want to be able to return a possibly different http response.

Visitor pattern source generator

· 5 min read

I am a big fan of the visitor pattern, I think it is a very good approach for adding behaviors to a group of classes without modifying all of them.

For example if we are building a compiler we may have an abstract syntax tree that represents the code that the compiler is compiling. Two different visitors can be, for example:

  • a type checker
  • a code emitter

Workflows with the visitor pattern

· 11 min read

Workflows

As a software developer I work, most of the times, on LOB applications that support some kind of process or workflow for a specific company. That means that there are some entities, such as customers, orders or support tickets, and that they evolve during the lifecycle of the application. For example we could have a CRM with a lead entity that evolves into a customer or we could track the state of a ticket: open -> analysis -> work -> deploy.