📒
Notes
Cloud ComputingData Science/AIGame Development
  • Home
  • Big O
  • Data Structures & Algorithms
    • Data Structures
      • Array
      • Stack
      • Queue
      • Linked List
      • Binary Tree
    • Algorithms
      • Searching
      • Sorting
      • Graphs
        • Searching
        • Minimum Spanning Tree
        • Shortest Path Algorithms
      • String Algorithms
  • Object Oriented Programming
  • Languages
    • HTML/CSS
      • CSS
    • C++
    • C#
      • Types
      • Keywords
        • Modifiers
          • Access Modifiers
        • Method Parameters
      • Operators and Expressions
      • Collections
      • Constructors
      • Delegates
      • Indexers
      • Concepts
      • Features
        • LINQ
          • Operators
          • Working with Data
          • Methods
          • Resources
        • Asynchronous Programming
        • Reflection
    • Dart
    • GraphQL
    • JavaScript
      • Variable and Parameter
      • Built-in objects
        • Array
        • Built-in Functions
      • Functions
      • Classes
      • Prototype
      • Libraries
        • jQuery
        • React
          • Components
          • State and Lifecycle
          • Hooks
            • useState
            • useEffect
          • Resources
      • Testing Framework
      • Web APIs
    • Kotlin
      • Basics
    • Python
      • Basics
      • Data Structures
      • Functions
      • Resources
        • Flask
    • SQL
      • Basics
      • Operators
      • JOINs
      • Aggregations
      • Subqueries
      • Views
      • Functions
        • Window Functions
      • Stored Procedures
      • Performance Tuning
      • Extras
    • Resources
  • 🌐Web Frameworks
    • Angular
      • Templates
      • Directives
        • Attribute Directives
        • Structural Directives
    • ASP.NET
      • Fundamentals
        • Dependency Injection
        • Middleware
        • Session & State Management
      • Web apps
        • MVC
          • Controllers
            • Filters
          • Models
            • Model Binding
            • Model Validation
          • Views
            • Tag Helpers
            • View Components
          • Features
        • Client-side development
      • Web APIs
        • Controller-based APIs
        • Minimal APIs
        • OpenAPI
        • Content Negotiation
      • SignalR
      • Host and Deploy
        • IIS
      • Security
    • Django
      • The Request/Response Cycle
    • Terminologies
      • Web Server
        • Internet Information Services
    • Resources
  • 📱App Frameworks
    • Introduction
      • Resources
    • Xamarin
      • Lifecycle
      • Custom Renderers & Effects
      • Behaviors
      • Triggers
      • Gestures
      • Commands
      • Dependency Service in XF
      • Libraries
      • Showcase
    • .NET MAUI
      • Controls
      • Navigation
      • Storage Options
  • Multi-Platform Frameworks
    • .NET
      • .NET Framework
        • ADO.NET
        • WCF
      • Fundamentals
        • Logging
        • Testing
      • Advanced
        • Asynchronous Programming
        • Parallel Programming
        • Threading
        • Memory Management
          • Garbage Collection
    • Flutter
  • Object-Relational Mappers
    • Entity Framework
      • Application Models
      • Configuration
      • Setting Up
      • Advanced
  • Databases
    • Introduction
      • DBMS Architecture
      • Normalization
      • Database Transaction Models
    • Relational Databases
      • Microsoft SQL Server
        • Basics
        • Functions
        • Stored Procedures
        • Error Handling
        • Log Shipping
        • Querying and Manipulating JSON data
        • Statements
        • Topics
        • Extras
    • Non-Relational Databases
      • MongoDB
      • Redis
        • Data Structures
        • Introduction
        • Managing Database
  • Tools
    • Version Control
      • Git
        • Setup and Config
        • Basics
          • Sharing and Updating Projects
        • Resources
      • Perforce Helix
    • GitHub
    • Powershell
  • Software Development
    • Software Development Life Cycle
    • Software Design Patterns
      • GoF Design Patterns
      • Architectural Patterns
        • MVC
        • MVVM
        • N-tier Architecture
        • Onion Architecture
        • Data Transfer Objects
      • CQRS
    • Software Design Principles
      • S.O.L.I.D. Priniciple
  • System Design
    • Topics
      • Load Balancing
  • Topics
    • JWT
    • Caching
      • Static vs Dynamic Caching
    • OSI model
      • HTTP
    • Glossary
    • API
      • SOAP
      • REST
    • Microservices
    • WebHooks
    • Practice
    • Operating Systems
      • Windows
    • Architecture
  • 🔖Bookmarks
  • 🔗Resources
Powered by GitBook
On this page
  • Creational Pattern
  • Factory Method
  • Object Pooling
  • Singleton
  • Structural Pattern
  • Behavioral Pattern
  • Command
  • Observer
  • State
  • Strategy

Was this helpful?

  1. Software Development
  2. Software Design Patterns

GoF Design Patterns

Gangs of Four Design Patterns

Creational Pattern

These patterns are designed for class instantiation. They can be either class-creational patterns or object-creational patterns.

Factory Method

  • The Factory method offers an interface for creating an instance of a class, with its subclasses deciding which class to instantiate.

public class CardGame {
    public static CardGame createCardGame(GameType type) {
        if(type == GameType.Poker) {
            return new PokerGame();
        }
        else if(type == GameType.BlackJack) {
            return new BlackJackGame();
        }
        return null;
    }
}

Object Pooling

Object pooling is a software creational design pattern that recycles objects rather than recreating them. It does that by holding selected objects in a pool ready for use when they are requested by an application.

This process helps to improve performance by minimizing unnecessary object creation.

Unity's ObjectPool class can be used, or custom pool managers can be implemented.

Singleton

  • The patterns main objective is to create only one instance of a class and to provide only one global access point to that object.

  • With this description, this design pattern perfectly fits in the category of the Creational Design Patterns, because at the end, we are creating an object, with only a single instance.

public sealed class NaiveSingleton {
    private static readonly object _lockInstance = new object();
    private static NaiveSingleton _instance = null;

    private NaiveSingleton() { ... }

    public static NaiveSingleton getInstance(){
        lock(_lockInstance){
            if (_instance == null)
                _instance = new NaiveSingleton();
            return _instance;
        }
    }
}
  • First, Singletons should always be a sealed in order to prevent class inheritance, which could end up with multiple instances which contradicts the purpose of Singleton.

  • Second, the constructor must also be private to prevent creating new instances.

Disadvantages

  • a.k.a. Anti-Pattern, because it can interfere with the unit testing and is inflexible.

Structural Pattern

These patterns are designed with regard to a class's structure and composition. The main goal pf most of these patterns is to increase the functionality of the class(es) involved, without changing much of its composition.

Behavioral Pattern

These patterns are designed depending on how one class communicates with others.

Command

The command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method, and values for the method parameters.

Observer

The Observer pattern allows an object (the subject) to notify its dependents (observers) of changes, typically through events or delegates.

In Unity, this pattern is frequently used for event handling, UI updates, and inter-component communication.

State

State is a behavioral design pattern that lets an object alter its behavior when its internal state changes. It appears as if the object changed its class.

Unity's Animator Controller provides a visual interface for creating state machines for character animations, but you can also implement custom state machines for game logic.

Strategy

Strategy is a behavioral design pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.

PreviousSoftware Design PatternsNextArchitectural Patterns

Last updated 3 months ago

Was this helpful?

LogoCommand Design Pattern Explained with C# Examples | Syncfusion BlogsSyncfusion Blogs
LogoDesign Patterns