Skip to content

Commit e74ca38

Browse files
authored
uploaded initial draft
1 parent b16f77e commit e74ca38

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

Design_Patterns.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Design Patterns for Beginners
2+
3+
## Introduction
4+
Design patterns are solutions to common problems encountered in software design. They provide a 'systematic' yet creative way to design and solve problems. When you're building software, you often face similar challenges, and design patterns offer a way to address these challenges in an efficient manner.
5+
6+
### Why Design Patterns?
7+
8+
1. **Reusability:** Design patterns promote code reusability. Once you understand and implement a design pattern, you can apply it to different projects and scenarios. Note that it is not a piece of code for you to copy and paste, but a certain way of thinking and solving problems.
9+
- But it is not the same as _algorithm_, whose input and output satisfy a certain specifications. Design Patterns are more creative and applicable in software development, in the sense that it does not require a strict specification on its input.
10+
11+
2. **Maintainability:** Using design patterns results in cleaner and more maintainable code. They encapsulate specific behaviors, making it easier to modify or extend functionalities without affecting the entire codebase.
12+
13+
3. **Scalability:** Design patterns contribute to scalable and flexible software architecture. They help in building systems that can adapt to changing requirements and scale gracefully.
14+
15+
16+
## Types of Design Patterns
17+
18+
### 1. Creational Patterns
19+
Creational patterns focus on object creation mechanisms, dealing with the process of object instantiation.
20+
21+
### 2. Structural Patterns
22+
Structural patterns are concerned with object composition, forming relationships between objects to create larger structures.
23+
24+
### 3. Behavioral Patterns
25+
Behavioral patterns define ways for objects to communicate, encapsulating patterns of communication between objects.
26+
27+
## Simple yet Powerful Example
28+
We briefly introduce a **Creational Pattern** to demonstrate how powerful and flexible design patterns are.
29+
30+
Suppose we are developing a software where transportation tools are involved. At first, we only support cars and busses. But as our product grows, we have the need to support more types of transportation tools, like airplanes and boats, etc. We can certainly create more classes, like we did for cars and busses. But sometimes all we care about is that they are methods of transportation, i.e., they can take people from one place to another place. Let's call that behavior `move()`.
31+
32+
Thus, we may define a shared interface between among these classes
33+
```python
34+
class Vehicle:
35+
def move(self):
36+
...
37+
```
38+
39+
We can then define
40+
```python
41+
class Airplane(Vehicle):
42+
def move(self):
43+
...
44+
```
45+
and
46+
```python
47+
class Car(Vehicle):
48+
def move(self):
49+
...
50+
```
51+
52+
53+
This way, we don't need to worry about the exact details of 'how a car/plane/bicycle' moves, but knowing that they support `move()` is good enough.
54+
55+
56+
## Helpful resources
57+
### Online Courses:
58+
- **Coursera - "Design Patterns" by the University of Alberta:**
59+
- This online course covers design patterns using Java. It includes video lectures, quizzes, and programming assignments to reinforce the concepts.
60+
61+
### Websites and Tutorials:
62+
63+
- **[Refactoring Guru - Design Patterns](https://refactoring.guru/design-patterns):**
64+
- This website provides a comprehensive guide to design patterns with examples in multiple programming languages. **EXTREMELY RECOMMENDED!**
65+
66+
67+
- **[DZone - Design Patterns Refcard](https://dzone.com/refcardz/design-patterns):**
68+
- DZone offers a concise reference card on design patterns, providing a quick overview of essential patterns.
69+
70+
### Online Communities:
71+
72+
- **[Stack Overflow - Design Patterns Questions](https://stackoverflow.com/questions/tagged/design-patterns):**
73+
- Stack Overflow is an excellent place to find answers to specific design pattern-related questions and engage with the programming community.
74+

0 commit comments

Comments
 (0)