Skip to content

Commit

Permalink
Fix docs style for github pages
Browse files Browse the repository at this point in the history
  • Loading branch information
vyahello committed Oct 14, 2020
1 parent 4695d29 commit 5ebb46c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Here **polymorphism** is often used.

### Factory method
Factory method defines an interface for creating an object but defers object instantiation to run time.

```python
from abc import ABC, abstractmethod

Expand Down Expand Up @@ -118,12 +119,14 @@ square: Shape = factory.shape()
print(square.__class__.__name__)
print(square.draw())
```

Factory encapsulates objects creation. Factory is an object that is specialized in creation of other objects.
- Benefits:
- Useful when you are not sure what kind of object you will be needed eventually.
- Application need to decide what class it has to use.
- Exercise:
- Pet shop is selling dogs but now it sells cats too.

```python
from abc import ABC, abstractmethod

Expand Down Expand Up @@ -325,6 +328,7 @@ Python has global variables and modules which are **_singletons_**. Singleton al
Useful if you want to share cached information to multiple objects.

**Classic singleton**

```python
from typing import Any, Dict

Expand Down Expand Up @@ -372,6 +376,7 @@ print(bar_one is bar_two)
```

**Borg singleton**

```python
from typing import Dict, Any

Expand Down Expand Up @@ -417,6 +422,7 @@ Builder reduces complexity of building objects.
- Product: object being built
- Exercise:
- Build a car object

```python
from abc import ABC, abstractmethod

Expand Down Expand Up @@ -1427,6 +1433,7 @@ Composite pattern is related to iterator pattern.
- Will iterate over a certain point based on client input

**Iterator function**

```python
from typing import Iterator, Tuple, List

Expand Down Expand Up @@ -1529,6 +1536,7 @@ This type of pattern decouples responsibility. Composite is related to this desi
- Successor
- Concrete Handler
- Checks if it can handle the request

```python
from abc import abstractmethod
from typing import List
Expand Down

0 comments on commit 5ebb46c

Please sign in to comment.