GDGoC: BZU - Design Patterns: No More Spaghetti Code
Slides for our Design Patterns Session, for more info: https://gdg.community.dev/events/details/google-gdg-on-campus-birzeit-university-birzeit-palestine-presents-design-patterns-no-more-spaghetti-code/
What are DesignPatterns?
1. Typical solution for occurring problem.
2. Not copy/paste and run.
3. General Concept, not algorithm.
Algorithm
Design Patterns
3.
Why Design Patterns?
1.Tried and tested solution.
2. Teaches principles of OOD (Object Oriented Design).
3. Common language.
4.
When?
1. When yourcode feels like spaghetti 🍝 (hard to read/maintain).
2. When multiple developers need to collaborate (common language).
3. When scaling your app (patterns ensure flexibility).
1. Every timea class is instantiated, a new object is created
2. Unnecessary memory usage and performance issues
3. Risk of data conflicts when sharing resources
Problem
19.
1. Ensures onlyone instance of a class is created.
2. The same object is shared across the application.
3. Prevents data conflicts and saves resources.
Solution - Singleton
1. Concurrent Access– Avoids conflicts when multiple processes access the object
2. Global Access Point – A single access point for consistency
3. Single Object – Centralized control and easier management
Why Use Singleton?
What NOT toDo: Anti-Patterns 🚫
1. Monolithic Class: One class doing everything.
2. Copy-Paste Programming: Duplicate code.
3. Pattern Overkill: Using Singleton for everything.