In this tutorial, you'll learn how to implement TypeState Pattern in Python. What is TypeState Pattern? The basic idea behind TypeState pattern is to encode the state information inside types. While TypeState pattern is a generic pattern that could be used in multiple languages, I encountered this pattern first while developing software using Rust.
Disclaimer: The details mentioned below are just my thoughts on an approach towards software correctness. I consider myself not to be an expert in Python, Rust, software verification, or in general software development.
Please use your own judgement when designing/implementing software. That said, I am interested in practices to make software safer, and would highly appreciate any constructive criticism/feedback.
The basic idea behind TypeState pattern is to encode the state information inside types.
While TypeState pattern is a generic pattern that could be used in multiple languages, I encountered this pattern first while developing software using Rust.
There are multitude of resources (see References below) that discuss TypeState pattern inside Rust in further detail, so I will not delve into details of TypeState pattern.
Let's explore an example API: say we have a connection API over which we could establish connections and communicate with web servers using HTTP. The connection can exist in two states: the connection to remote end has not been established, and the connection to remote end has been established. There can be more than two states for the connection, but for this example, we will consider only these two states.
In this post, we'll learn top 30 Python Tips and Tricks for Beginners
Guide to Python Programming Language
You can learn how to use Lambda,Map,Filter function in python with Advance code examples. Please read this article
In this tutorial, we'll learn Builder Design Pattern. Builder Design Pattern is one of the Creational Design Pattern which helps in constructing the complex object like DOM, XML Document and other complex object
In this tutorial, we'll learn Python Tips and Tricks for Competitive Programming. Let's explore it with us now.