Skip to content

Commit 62b5ad3

Browse files
committed
Polish structure of documentation
1 parent a9ef299 commit 62b5ad3

File tree

1 file changed

+90
-61
lines changed

1 file changed

+90
-61
lines changed

README.md

Lines changed: 90 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
# Python OOD
2-
Describes most useful python design patterns.
2+
> Describes most useful python design patterns.
33
44
[![Build Status](https://api.travis-ci.org/vyahello/python-ood.svg?branch=master)](https://travis-ci.org/vyahello/python-ood)
55

6+
**Tools**
7+
> - `python 3+` basis
8+
> - `pylint` code analyser
9+
> - `black` code formatter
10+
> - `travis CI`
11+
>
12+
> All code is fully type annotated ⭐
613
14+
## Table of contents
715
- [Creational](#creational)
816
- [Factory method](#factory-method)
917
- [Abstract factory](#abstract-factory)
@@ -25,11 +33,17 @@ Describes most useful python design patterns.
2533
- [Strategy](#strategy)
2634
- [Chain of responsibility](#chain-of-responsibility)
2735
- [Other qualities](#other-qualities)
36+
- [Development notes](#development-notes)
37+
- [Release notes](#release-notes)
38+
- [Meta](#meta)
39+
- [Contributing](#contributing)
2840

2941
## Creational
30-
Used to create objects in a systematic way. Supports flexibility and different subtypes of objects from the same class at runtime. Here polymorphism is often used.
42+
Creational types of patterns used to create objects in a systematic way. Supports flexibility and different subtypes of objects from the same class at runtime.
43+
Here **_polymorphism_** is often used.
44+
3145
### Factory method
32-
Define an interface for creating an object but defer object instantiation to run time.
46+
Factory method defines an interface for creating an object but defers object instantiation to run time.
3347
```python
3448
from abc import ABC, abstractmethod
3549

@@ -139,14 +153,14 @@ get_pet('cat')
139153

140154
```
141155
### Abstract factory
142-
Client expects to receive family related objects. But dont have to know which family it is until run time. Abstract factory is related to factory method and concrete product are singletons.
143-
- Participants:
144-
- Abstract factory: pet factory.
145-
- Concrete factory: dog factory and cat factory.
146-
- Abstract product.
147-
- Concrete product: dog and dog food, cat and cat food.
156+
In abstract factory a client expects to receive family related objects. But don't have to know which family it is until run time. Abstract factory is related to factory method and concrete product are singletons.
157+
- Implementation idea:
158+
- Abstract factory: pet factory
159+
- Concrete factory: dog factory and cat factory
160+
- Abstract product
161+
- Concrete product: dog and dog food, cat and cat food
148162
- Exercise:
149-
We have a Pet factory (which includes Dog and Cat factory and both factories produced related products such as Dog and Cat food and we have a PetFactory which gets Cat or Dog factory).
163+
- We have a Pet factory (which includes Dog and Cat factory and both factories produced related products such as Dog and Cat food and we have a PetFactory which gets Cat or Dog factory).
150164

151165
```python
152166
from abc import ABC, abstractmethod
@@ -286,10 +300,10 @@ store.show_pet()
286300

287301
```
288302
### Singleton
289-
Global variable, modules - singleton. Allows only one object to be instantiated from a class template.
290-
If you want to share cached information to multiple objects.
303+
Python has global variables and modules which are **_singletons_**. Singleton allows only one object to be instantiated from a class template.
304+
Useful if you want to share cached information to multiple objects.
291305

292-
Classic singleton
306+
**Classic singleton**
293307
```python
294308
class Singleton:
295309
"""Makes all instances as the same object."""
@@ -333,7 +347,7 @@ print(id(bar_two))
333347
print(bar_one is bar_two)
334348
```
335349

336-
Borg singleton
350+
**Borg singleton**
337351
```python
338352
from typing import Any
339353

@@ -369,13 +383,14 @@ print(y)
369383
```
370384

371385
### Builder
372-
Reduces complexity of building objects.
386+
Builder reduces complexity of building objects.
373387
- Participants:
374-
- Director.
375-
- Abstract Builder: interfaces.
376-
- Concrete Builder: implements the interfaces.
377-
- Product: object being built.
378-
- Exercise to to build a car object.
388+
- Director
389+
- Abstract Builder: interfaces
390+
- Concrete Builder: implements the interfaces
391+
- Product: object being built
392+
- Exercise:
393+
- Build a car object
379394

380395
```python
381396
from abc import ABC, abstractmethod
@@ -463,12 +478,12 @@ print(car.summary())
463478

464479
```
465480
### Prototype
466-
Prototype patterns is related to abstract factory pattern.
481+
Prototype patterns are related to abstract factory pattern.
467482
- Ideas:
468-
- Clone objects according to prototypical instance.
469-
- Creating many identical objects individually.
470-
- Clone individual objects.
471-
- Create a prototypical instance first.
483+
- Clone objects according to prototypical instance.
484+
- Creating many identical objects individually.
485+
- Clone individual objects
486+
- Create a prototypical instance first
472487
- Exercise:
473488
- Use the same car if car has same color or options, you can clone objects instead of creating individual objects
474489

@@ -527,13 +542,14 @@ print(cloned_car.summary())
527542
```
528543

529544
## Structural
530-
Establish useful relationships between software components. Here inheritance is often used.
531-
- Route maps the user request to a `Controller` which...
532-
- Uses the `Model` to retrieve all of the necessary data, organizes it and send it off to the...
533-
- View, which then uses that data to render the web page.
545+
Structural type of patterns establish useful relationships between software components. Here **_inheritance_** is often used.
546+
- Ideas:
547+
- Route maps the user request to a `Controller` which...
548+
- Uses the `Model` to retrieve all of the necessary data, organizes it and send it off to the...
549+
- View, which then uses that data to render the web page
534550

535551
### MVC
536-
UI pattern intended to separate internal representation of data from ways it is presented to/accepted from the user
552+
MVC (Model-View-Controller) is a UI pattern intended to separate internal representation of data from ways it is presented to/from the user.
537553

538554
```python
539555
from abc import ABC, abstractmethod
@@ -703,11 +719,11 @@ if __name__ == "__main__":
703719
```
704720

705721
### Decorator
706-
Add new feature to an existing object. Supports dynamic changes.
722+
Decorator type of patterns add new feature to an existing object. Supports dynamic changes.
707723
- Exercise:
708724
- Add additional message to an existing function
709725

710-
Decorator function
726+
**Decorator function**
711727
```python
712728
from functools import wraps
713729
from typing import Callable
@@ -735,7 +751,7 @@ print(hello_world.__name__)
735751
print(hello_world.__doc__)
736752
```
737753

738-
Decorator class
754+
**Decorator class**
739755
```python
740756
from abc import ABC, abstractmethod
741757

@@ -786,7 +802,7 @@ print(sum_float.value())
786802
```
787803

788804
### Proxy
789-
Postpone object creation unless it is necessary. Object is too expensive (resource intensive) to create that's why we have to create it if it is needed.
805+
Proxy patterns postpones object creation unless it is necessary. Object is too expensive (resource intensive) to create that's why we have to create it once it is needed.
790806
- Participants:
791807
- Producer
792808
- Artist
@@ -841,11 +857,11 @@ proxy.produce()
841857
```
842858

843859
### Adapter
844-
Converts interface of a class into another one a client is expecting.
860+
Adapter patterns converts interface of a class into another one a client is expecting.
845861
- Exercise:
846-
- Korean language: speak_korean()
847-
- British language: speak_english()
848-
- Client has to have uniform interface - speak method()
862+
- Korean language: `speak_korean()`
863+
- British language: `speak_english()`
864+
- Client has to have uniform interface - `speak method`
849865
- Solution:
850866
- Use an adapter pattern that translates method name between client and the server code
851867

@@ -914,7 +930,7 @@ for speaker in speakers:
914930
- Participants:
915931
- Component - abstract 'class'
916932
- Child - inherits from Component 'class'
917-
- Composite - inherits from component 'class'. Maintain child objects by adding.removing them.
933+
- Composite - inherits from component 'class'. Maintain child objects by adding.removing them
918934

919935
```python
920936
from abc import ABC, abstractmethod
@@ -978,7 +994,8 @@ top_menu.function()
978994
```
979995

980996
### Bridge
981-
Separates the abstraction into different class hierarchies. Abstract factory and adapter patterns are related to this Bridge design pattern.
997+
Bridge pattern separates the abstraction into different class hierarchies.
998+
Abstract factory and adapter patterns are related to Bridge design pattern.
982999

9831000
```python
9841001
from abc import ABC, abstractmethod
@@ -1043,7 +1060,8 @@ circle_two.draw()
10431060
```
10441061

10451062
### Facade
1046-
The Facade pattern is a way to provide a simpler unified interface to a more complex system. It provides an easier way to access functions of the underlying system by providing a single entry point.
1063+
The Facade pattern is a way to provide a simpler unified interface to a more complex system.
1064+
It provides an easier way to access functions of the underlying system by providing a single entry point.
10471065

10481066
```python
10491067
from typing import Tuple, Iterator
@@ -1185,13 +1203,13 @@ test_suite.run()
11851203
```
11861204

11871205
## Behavioral
1188-
Best practices of objects interaction. Methods and signatures are often used.
1206+
Behavioral patterns provide best practices of objects interaction. Methods and signatures are often used.
11891207

11901208
### Observer
1191-
Establishes one yo many relationship between subject and multiple observers. Singleton is related to observer design pattern.
1209+
Observer pattern establishes one to many relationship between subject and multiple observers. Singleton is related to observer design pattern.
11921210
- Exercise:
1193-
- Subjects need to be monitored.
1194-
- Observers need to be notified.
1211+
- Subjects need to be monitored
1212+
- Observers need to be notified
11951213
- Participants:
11961214
- Subject: abstract class
11971215
- Attach
@@ -1262,7 +1280,7 @@ subject_one.notify()
12621280
```
12631281

12641282
### Visitor
1265-
Add new features to existing hierarchy without changing it. Add new operations to existing classes dynamically.
1283+
Visitor pattern adds new features to existing hierarchy without changing it. Add new operations to existing classes dynamically.
12661284
Exercise:
12671285
- House class:
12681286
- HVAC specialist: Visitor type 1
@@ -1339,10 +1357,10 @@ home.accept(electrician)
13391357
### Iterator
13401358
Composite pattern is related to iterator pattern.
13411359
- Exercise:
1342-
- Our custom iterator based on a build-in python iterator: `zip()`.
1343-
- Will iterate over a certain point baed on client input.
1360+
- Our custom iterator based on a build-in python iterator: `zip()`
1361+
- Will iterate over a certain point based on client input
13441362

1345-
Iterator function
1363+
**Iterator function**
13461364
```python
13471365
from typing import Iterator, Tuple
13481366

@@ -1359,7 +1377,7 @@ for number in count_to(3):
13591377
print("{} in german is {}".format(*number))
13601378
```
13611379

1362-
Iterator class
1380+
**Iterator class**
13631381
```python
13641382
from typing import Iterator
13651383

@@ -1383,7 +1401,7 @@ for _ in range(10):
13831401
```
13841402

13851403
### Strategy
1386-
Dynamically changing the behavior of an object. Add dynamically objects with `types` module.
1404+
Strategy patterns used to dynamically change the behavior of an object. Add dynamically objects with `types` module.
13871405
- Participants:
13881406
- Abstract strategy class with default set of behaviors
13891407
- Concrete strategy class with new behaviors
@@ -1436,7 +1454,7 @@ second_strategy.execute()
14361454
```
14371455

14381456
### Chain of responsibility
1439-
Decouple responsibility. Composite is related to this design pattern.
1457+
Thiss type of pattern decouples responsibility. Composite is related to this design pattern.
14401458
- Exercise:
14411459
- Integer value
14421460
- Handlers
@@ -1514,14 +1532,25 @@ c.delegate(requests)
15141532

15151533
**Cohesion** refers to how independent the software component is. More cohesion is better.
15161534

1535+
## Development notes
1536+
1537+
### Release notes
1538+
1539+
* 0.1.1
1540+
* Polish documentation
1541+
* 0.1.0
1542+
* Distribute first version of a project
1543+
1544+
### Meta
1545+
Author – Volodymyr Yahello vyahello@gmail.com
1546+
1547+
Distributed under the `MIT` license. See [LICENSE](LICENSE.md) for more information.
15171548

1518-
## Contributing
1549+
You can reach out me at:
1550+
* [https://github.com/vyahello](https://github.com/vyahello)
1551+
* [https://www.linkedin.com/in/volodymyr-yahello-821746127](https://www.linkedin.com/in/volodymyr-yahello-821746127)
15191552

1520-
### Setup
1521-
- clone the repository
1522-
- configure Git for the first time after cloning with your name and email
1523-
```bash
1524-
git config --local user.name "Volodymyr Yahello"
1525-
git config --local user.email "vyahello@gmail.com"
1526-
```
1527-
- `python3.6` is required to run the code
1553+
### Contributing
1554+
1. clone the repository
1555+
2. configure Git for the first time after cloning with your `name` and `email`
1556+
3. `pip install -r requirements.txt` to install all project dependencies

0 commit comments

Comments
 (0)