The Agile Way

The Agile Way

Share this post

The Agile Way
The Agile Way
Software Design Pattern By Example: Singleton
Copy link
Facebook
Email
Notes
More

Software Design Pattern By Example: Singleton

Explain Design Pattern in easy-to-understand example

Zhimin Zhan's avatar
Zhimin Zhan
Nov 14, 2022
∙ Paid
1

Share this post

The Agile Way
The Agile Way
Software Design Pattern By Example: Singleton
Copy link
Facebook
Email
Notes
More
Share

A repost of my past article on Medium.

(I know most of this blog’s readers are testers or automation/DevOps engineers. This one is about software design.)

Design Patterns are good practices of Object-Oriented (OO) Software Design. Applying appropriate design patterns will help to design your software better. However, design patterns are not easy to master, it was the case for me, and my daughter when she started an IT degree at Uni. I wrote a series of articles to help her learn Design Patterns quickly. My approach is to use easy-to-understand exercises, which I believe is an easier way to master design patterns. This article’s pattern is Singleton.

The implementation language will be C++, but you can try another OO language such as Java and Ruby.

Table of Contents:
· The Problem
· Analyse
· Sub-optimal Designs
  ∘ Static Method
  ∘ Static Member
· Singleton Pattern
  ∘ How does it work?

The Problem

In your application, the unique identifier of the machine (runs the program) is frequently used in the code. Considering getting a machine identifier is a relatively expensive operation (let’s say 1 second), how will you design the getMachineId() function?

Keep reading with a 7-day free trial

Subscribe to The Agile Way to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Zhimin Zhan
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More