Skip to content

Latest commit

 

History

History

command

Command Design Pattern

Videos

Section Video Links
Command Overview Command Overview Command Overview Command Overview
Command Use Case Command Use Case Command Use Case Command Use Case
Single Leading Underscore Single Leading Underscore Single Leading Underscore Single Leading Underscore

Book

Cover Links
Design Patterns In Python (ASIN : B08XLJ8Z2J)    https://www.amazon.com/dp/B08XLJ8Z2J
   https://www.amazon.co.uk/dp/B08XLJ8Z2J
   https://www.amazon.in/dp/B08Z282SBC
   https://www.amazon.de/dp/B08XLJ8Z2J
   https://www.amazon.fr/dp/B08XLJ8Z2J
   https://www.amazon.es/dp/B08XLJ8Z2J
   https://www.amazon.it/dp/B08XLJ8Z2J
   https://www.amazon.co.jp/dp/B08XLJ8Z2J
   https://www.amazon.ca/dp/B08XLJ8Z2J
   https://www.amazon.com.au/dp/B08Z282SBC

Overview

... Refer to Book or Design Patterns In Python website to read textual content.

Terminology

... Refer to Book or Design Patterns In Python website to read textual content.

Command Pattern UML Diagram

The Command Pattern UML Diagram

Source Code

... Refer to Book or Design Patterns In Python website to read textual content.

Output

python ./command/command_concept.py
Executing Command 1
Executing Command 2
Executing Command 1
Executing Command 2

Example Use Case

... Refer to Book or Design Patterns In Python website to read textual content.

Example UML Diagram

The Command Pattern UML Diagram

Output

python ./command/client.py
Light turned ON
Light turned OFF
Light turned ON
Light turned OFF
11:23:35 : ON
11:23:35 : OFF
11:23:35 : ON
11:23:35 : OFF
Light turned ON
Light turned OFF

New Coding Concepts

_Single Leading Underscore

The single leading underscore _variable, on your class variables is a useful indicator to other developers that this property should be considered private.

Private, in C style languages, means that the variable/field/property is hidden and cannot be accessed outside of the class. It can only be used internally by its own class methods.

Python does not have a public/private accessor concept so the variable is not actually private and can still be used outside of the class in other modules.

It is just a useful construct that you will see developers use as a recommendation not to reference this variable directly outside of this class, but use a dedicated method or property instead.

Summary

... Refer to Book or Design Patterns In Python website to read textual content.