From 14a7f6460a47884d9406919cccab92bb7b8f6c77 Mon Sep 17 00:00:00 2001 From: theartcher Date: Wed, 22 Oct 2025 10:05:46 +0200 Subject: [PATCH 1/5] Add basic page and code guides --- DesignPatternPedia/README.md | 59 +++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/DesignPatternPedia/README.md b/DesignPatternPedia/README.md index 0b59536..014994f 100644 --- a/DesignPatternPedia/README.md +++ b/DesignPatternPedia/README.md @@ -1,18 +1,67 @@ -# Website +# DesignPatternPedia + +- [DesignPatternPedia](#designpatternpedia) + - [Page Structure](#page-structure) + - [Coding Standards](#coding-standards) + - [Installation](#installation) + - [Build and serve](#build-and-serve) This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator. +## Page Structure + +Each page follows a basic structure to ensure that a user can easily find metadata on a certain design pattern. These elements include; + +1. The name of the design pattern. + 1. Include extra used names or alternative names used just below the title itself. +2. The group the design pattern belongs to. + 1. Creational, Structural or Behavioral +3. Description + 1. A short paragraph explaining, in simple terms, what the pattern is about. +4. An up-to-date table of contents. +5. Problem statement + 1. A small real-life example of why this can be a problem. +6. Potential solution + 1. An analogy or metaphor to explain in human terms how the pattern works. +7. Examples + 1. Real world examples of application of the pattern. +8. Pros and cons + 1. Pros and cons of the pattern. +9. Your turn +10. How can the user see a potential implementation plan. +11. Code samples +12. Snippets in various programming languages. +13. Playground + 1. A 'playground' to get a 'feel' for the pattern. + +Some extras, common elements may include; + +1. A diagram or image explaining the pattern. +2. Relations or uses in other design patterns. + +## Coding Standards + +1. All images are put into an `/img` directory and not embedded directly. +2. All images have `alt` texts explaining their purpose and contents. +3. All basic page elements that can be re-used should be turned into components. +4. Code is written in American English. +5. Page content is written in Queens English. +6. All pages are `.mdx` files. +7. Code compiles and tests pass. +8. Directories follow the correct pattern structure. +9. Each page is built using the [page structure](#page-structure). + ## Installation -```bash +````bash npm i -``` +```s -## Local Development +### Local Development ```bash npm run start -``` +```` This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. From bfa2946143291dea65f2672a2ad239f667e8df9f Mon Sep 17 00:00:00 2001 From: theartcher Date: Wed, 22 Oct 2025 14:39:05 +0200 Subject: [PATCH 2/5] Enhance README and add new components for pattern tagging and pros/cons display - Updated README to include new sections for Local Development and Contributing. - Introduced PatternAliasAndTag component for tagging design patterns. - Added TwoColumnProsCons component to display pros and cons in a structured format. - Created associated CSS modules for styling the new components. - Updated docusaurus configuration for project details and GitHub links. --- DesignPatternPedia/README.md | 25 ++-- .../docs/Creational/singleton.mdx | 127 +++++++++++++++++- DesignPatternPedia/docusaurus.config.ts | 73 ++-------- .../pattern-alias-and-tag.module.css | 107 +++++++++++++++ .../pattern-alias-and-tag.tsx | 77 +++++++++++ .../pattern-page-features/pros-and-cons.tsx | 49 +++++++ .../two-column-pros-cons.module.css | 84 ++++++++++++ 7 files changed, 470 insertions(+), 72 deletions(-) create mode 100644 DesignPatternPedia/src/components/pattern-page-features/pattern-alias-and-tag.module.css create mode 100644 DesignPatternPedia/src/components/pattern-page-features/pattern-alias-and-tag.tsx create mode 100644 DesignPatternPedia/src/components/pattern-page-features/pros-and-cons.tsx create mode 100644 DesignPatternPedia/src/components/pattern-page-features/two-column-pros-cons.module.css diff --git a/DesignPatternPedia/README.md b/DesignPatternPedia/README.md index 014994f..e865ae0 100644 --- a/DesignPatternPedia/README.md +++ b/DesignPatternPedia/README.md @@ -4,7 +4,9 @@ - [Page Structure](#page-structure) - [Coding Standards](#coding-standards) - [Installation](#installation) + - [Local Development](#local-development) - [Build and serve](#build-and-serve) + - [Contributing](#contributing) This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator. @@ -46,22 +48,25 @@ Some extras, common elements may include; 3. All basic page elements that can be re-used should be turned into components. 4. Code is written in American English. 5. Page content is written in Queens English. -6. All pages are `.mdx` files. -7. Code compiles and tests pass. -8. Directories follow the correct pattern structure. -9. Each page is built using the [page structure](#page-structure). +6. Page content is cited, sourced, and referenced where deemed necessary. +7. All docs/pages are `.mdx` files. +8. Code compiles and tests pass. +9. Directories follow the correct pattern structure. +10. Each page is built using the [page structure](#page-structure). ## Installation -````bash - npm i -```s +To install the required packages and otherwise dependencies, run the following command; + +```bash +npm i +``` ### Local Development ```bash npm run start -```` +``` This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. @@ -78,3 +83,7 @@ And then to serve the newly created build, simply run. ```bash npm run serve ``` + +## Contributing + +Would you like to propose changes to the pattern-wiki? Then feel free to create a pull request in this repository. Make sure that your PR follows the standards as set in the [coding standards](#coding-standards) and [page structure](#page-structure). These standards ensure that the wiki is of high quality and that both the users and developers can find the right information quickly. diff --git a/DesignPatternPedia/docs/Creational/singleton.mdx b/DesignPatternPedia/docs/Creational/singleton.mdx index c58cb85..4bc2f26 100644 --- a/DesignPatternPedia/docs/Creational/singleton.mdx +++ b/DesignPatternPedia/docs/Creational/singleton.mdx @@ -1,5 +1,130 @@ --- title: Singleton +hide_title: true --- -This page describes the singleton pattern +import { CreationalPatternTag } from "@site/src/components/pattern-page-features/pattern-alias-and-tag"; +import TwoColumnProsCons from "@site/src/components/pattern-page-features/pros-and-cons"; +import TOCInline from '@theme/TOCInline'; + + + +--- + +The **Singleton** pattern ensures that a class has only one instance throughout the lifetime of an application and provides a single, well-known global access point to that instance. It’s one of the simplest creational design patterns, often used to control access to shared resources or global states, such as configuration objects, loggers, or connection pools. + +## 🧩The problem +Some components in a system are meant to exist only once. For example, imagine a +logging service that writes messages to a single log file. If each part of an +application created its own logger instance, messages could become disorganized, +duplicated, or even lost. Similarly, in database connections or system-wide +configuration management, having multiple instances could cause conflicts or +inconsistent behavior. The challenge is to guarantee that a single instance of a class can be created and accessed in a well-defined manner, without scattering global variables around. + +## 🛠️Solutions + +The Singleton pattern introduces a way to manage this shared instance explicitly. The class itself controls its instantiation by: + +- Making the constructor private or protected, thus preventing direct creation with `new`. +- Exposing a static method (`getInstance()`) that acts as a single point of access. +- Storing the one and only instance inside a static variable within the class. + +In essence, Singleton turns a regular class into both a **factory** and a **unique data holder**. + + +