Skip to content

Commit a985feb

Browse files
committed
Use helper class ABC instead of metaclass ABCMeta
1 parent 43676e7 commit a985feb

13 files changed

Lines changed: 32 additions & 32 deletions

File tree

src/AbstractFactory/Structural/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313

1414
from __future__ import annotations
15-
from abc import ABCMeta, abstractmethod
15+
from abc import ABC, abstractmethod
1616

1717

18-
class AbstractFactory(metaclass=ABCMeta):
18+
class AbstractFactory(ABC):
1919
"""
2020
EN: The Abstract Factory interface declares a set of methods that return
2121
different abstract products. These products are called a family and are
@@ -84,7 +84,7 @@ def create_product_b(self) -> ConcreteProductB2:
8484
"""
8585

8686

87-
class AbstractProductA(metaclass=ABCMeta):
87+
class AbstractProductA(ABC):
8888
@abstractmethod
8989
def useful_function_a(self) -> str:
9090
pass
@@ -107,7 +107,7 @@ def useful_function_a(self) -> str:
107107
return "The result of the product A2."
108108

109109

110-
class AbstractProductB(metaclass=ABCMeta):
110+
class AbstractProductB(ABC):
111111
"""
112112
EN: Here's the the base interface of another product. All products can interact with
113113
each other, but proper interaction is possible only between products of the

src/Builder/Structural/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414

1515
from __future__ import annotations
16-
from abc import ABCMeta, abstractmethod, abstractproperty
16+
from abc import ABC, abstractmethod, abstractproperty
1717
from typing import Any
1818

1919

20-
class Builder(metaclass=ABCMeta):
20+
class Builder(ABC):
2121
"""
2222
EN: The Builder interface specifies methods for creating the different parts
2323
of the Product objects.

src/ChainOfResponsibility/Structural/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"""
1515

1616
from __future__ import annotations
17-
from abc import ABCMeta, abstractmethod
17+
from abc import ABC, abstractmethod
1818
from typing import Any, Optional
1919

2020

21-
class Handler(metaclass=ABCMeta):
21+
class Handler(ABC):
2222
"""
2323
EN: The Handler interface declares a method for building the chain of
2424
handlers. It also declares a method for executing a request.

src/Command/Structural/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515

1616
from __future__ import annotations
17-
from abc import ABCMeta, abstractmethod
17+
from abc import ABC, abstractmethod
1818

1919

20-
class Command(metaclass=ABCMeta):
20+
class Command(ABC):
2121
"""
2222
EN: The Command interface declares a method for executing a command.
2323

src/FactoryMethod/Structural/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515

1616
from __future__ import annotations
17-
from abc import ABCMeta, abstractmethod
17+
from abc import ABC, abstractmethod
1818

1919

20-
class Creator(metaclass=ABCMeta):
20+
class Creator(ABC):
2121
"""
2222
EN: The Creator class declares the factory method that is supposed to return
2323
an object of a Product class. The Creator's subclasses usually provide the
@@ -100,7 +100,7 @@ def factory_method(self) -> ConcreteProduct2:
100100
return ConcreteProduct2()
101101

102102

103-
class Product(metaclass=ABCMeta):
103+
class Product(ABC):
104104
"""
105105
EN: The Product interface declares the operations that all concrete products
106106
must implement.

src/Mediator/Structural/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616

1717
from __future__ import annotations
18-
from abc import ABCMeta
18+
from abc import ABC
1919

2020

21-
class Mediator(metaclass=ABCMeta):
21+
class Mediator(ABC):
2222
"""
2323
EN: The Mediator interface declares a method used by components to notify the
2424
mediator about various events. The Mediator may react to these events and

src/Memento/Structural/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
from __future__ import annotations
16-
from abc import ABCMeta, abstractmethod
16+
from abc import ABC, abstractmethod
1717
from datetime import datetime
1818
from random import sample
1919
from string import ascii_letters, digits
@@ -81,7 +81,7 @@ def restore(self, memento: Memento) -> None:
8181
print(f"Originator: My state has changed to: {self._state}")
8282

8383

84-
class Memento(metaclass=ABCMeta):
84+
class Memento(ABC):
8585
"""
8686
EN: The Memento interface provides a way to retrieve the memento's metadata,
8787
such as creation date or name. However, it doesn't expose the Originator's

src/Observer/Structural/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626

2727
from __future__ import annotations
28-
from abc import ABCMeta, abstractmethod
28+
from abc import ABC, abstractmethod
2929
from random import randrange
3030
from typing import List
3131

3232

33-
class Subject(metaclass=ABCMeta):
33+
class Subject(ABC):
3434
"""
3535
EN: The Subject owns some important state and notifies observers when the
3636
state changes.
@@ -52,7 +52,7 @@ def notify(self) -> None:
5252
pass
5353

5454

55-
class Observer(metaclass=ABCMeta):
55+
class Observer(ABC):
5656
@abstractmethod
5757
def update(self, subject: Subject) -> None:
5858
pass

src/Proxy/Structural/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"""
1313

1414

15-
from abc import ABCMeta, abstractmethod
15+
from abc import ABC, abstractmethod
1616

1717

18-
class Subject(metaclass=ABCMeta):
18+
class Subject(ABC):
1919
"""
2020
EN: The Subject interface declares common operations for both RealSubject and
2121
the Proxy. As long as the client works with RealSubject using this interface,

src/State/Structural/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313

1414
from __future__ import annotations
15-
from abc import ABCMeta, abstractmethod
15+
from abc import ABC, abstractmethod
1616

1717

18-
class Context(metaclass=ABCMeta):
18+
class Context(ABC):
1919
"""
2020
EN: The Context defines the interface of interest to clients. It also
2121
maintains a reference to an instance of a State subclass, which represents
@@ -62,7 +62,7 @@ def request2(self):
6262
self._state.handle2()
6363

6464

65-
class State(metaclass=ABCMeta):
65+
class State(ABC):
6666
"""
6767
EN: The base State class declares methods that all Concrete State should
6868
implement and also provides a backreference to the Context object, associated

0 commit comments

Comments
 (0)