mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
27 lines
837 B
Python
27 lines
837 B
Python
from dataclasses import dataclass
|
|
|
|
from structural.bridge.IImplementation import Implementation
|
|
|
|
|
|
@dataclass
|
|
class Abstraction:
|
|
"""
|
|
The Abstraction defines the interface for the "control" part of the two
|
|
class hierarchies. It maintains a reference to an object of the
|
|
Implementation hierarchy and delegates all of the real work to this object.
|
|
"""
|
|
|
|
implementation: Implementation
|
|
|
|
def operation(self) -> str:
|
|
return f"Abstraction: Base operation with:\n{self.implementation.operation_implementation()}"
|
|
|
|
|
|
class ExtendedAbstraction(Abstraction):
|
|
"""
|
|
You can extend the Abstraction without changing the Implementation classes.
|
|
"""
|
|
|
|
def operation(self) -> str:
|
|
return f"""ExtendedAbstraction: Extended operation with:\n
|
|
{self.implementation.operation_implementation()}"""
|