Skip to content

Latest commit

 

History

History
 
 

bridge

Bridge Design Pattern

Videos

Section Video Links
Bridge Overview Bridge Overview  Bridge Overview  Bridge Overview 
Bridge Use Case Bridge Use Case  Bridge Use Case  Bridge Use Case 
Python Tuple Python Tuple  Python Tuple  Python Tuple 
Python *args Python *args  Python *args  Python *args 

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, pause Video Lectures or subscribe to Medium Membership to read textual content.

Terminology

... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.

Bridge UML Diagram

Bridge Pattern UML Diagram

Source Code

... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.

Output

python ./bridge/bridge_concept.py
('a', 'b', 'c')
a
b
c

Example Use Case

... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.

Example UML Diagram

Bridge Pattern in Context

Output

python ./bridge/client.py
    ******
  **      **
 *          *

*            *
*            *

 *          *
  **      **
    ******
**************

*            *
*            *
*            *
*            *
*            *
*            *

**************

New Coding Concepts

The *args Argument.

The *args argument takes all arguments that were sent to this method, and packs them into a Tuple.

It is useful when you don't know how many arguments, or what types, will be sent to a method, and you want the method to support any number of arguments or types being sent to it.

If you want your method to be strict about the types that it can accept, the set it specifically to accept List, Dictionary, Set or Tuple, and treat the argument as such within the method body, but the *args argument is another common option that you will see in source code throughout the internet.

E.g., when using the *args in your method signature, you can call it with any number of arguments of any type.

def my_method(*args):
    for arg in args:
        print(arg)

my_method(1, 22, [3], {4})

Outputs

1
22
[3]
{4}

Python Tuple

A Python Tuple is similar to a List. Except that the items in the Tuple are ordered, unchangeable and allow duplicates.

A Tuple can be instantiated using the round brackets () or tuple() , verses [] for a List and {} for a Set or Dictionary.

PS> python
>>> items = ("alpha", "bravo", "charlie", "alpha")
>>> print(items)
('alpha', 'bravo', 'charlie', 'alpha')
>>> print(len(items))
4

Summary

... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.