design-patterns/structural/bridge/main.py
Ruidy c8cc1f47b8
Observer (#20)
* doc: create package & update general TOCs

* doc: add documentation

* add code example

* reformat using black
2020-10-06 08:25:18 +02:00

33 lines
900 B
Python

"""
The client code should be able to work with any pre-configured abstraction-
implementation combination.
"""
from structural.bridge.abstractions import Abstraction
from structural.bridge.implementations import (
ConcreteImplementationA,
ConcreteImplementationB,
)
def client_code(abstraction: Abstraction) -> None:
"""
Except for the initialization phase, where an Abstraction object gets
linked with a specific Implementation object, the client code should only
depend on the Abstraction class. This way the client code can support any
abstraction-implementation combination.
"""
print(abstraction.operation(), end="")
implementation = ConcreteImplementationA()
abstraction = Abstraction(implementation)
client_code(abstraction)
print("\n")
implementation = ConcreteImplementationB()
abstraction = Abstraction(implementation)
client_code(abstraction)