Last active
November 22, 2021 11:20
-
-
Save pintman/24f7d01e9892ad36b4dc8a59a6ac7aa1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABC, abstractmethod | |
# abc = abstract base class | |
# Klassen, die von ABC erben, sind selbst abstrakt | |
class BaseGate(ABC): | |
# Deklaration einer abstrakten Methode | |
@abstractmethod | |
def perform(self) -> bool: | |
... | |
# AndGate erbt von BaseGate | |
class AndGate(BaseGate): | |
def __init__(self): | |
# Attribute werden mit self referenziert | |
self.inputOne = False | |
self.inputTwo = False | |
# jede Instanzmethode hat self als ersten Parameter | |
def perfom(self): | |
return self.inputOne and self.inputTwo | |
class NotGate(BaseGate): | |
def __init__(self): | |
self.inp = False | |
def perform(self): | |
return not self.inp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment