mirror of
https://github.com/robindhole/fundamentals.git
synced 2025-09-14 11:02:23 +00:00
Adds python code (#7)
This commit is contained in:

committed by
GitHub

parent
8c24d0345a
commit
59d2d5acfb
14
python_code/oop/SOLID/bird/Bird.py
Normal file
14
python_code/oop/SOLID/bird/Bird.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import BirdType
|
||||
|
||||
class Bird(ABC):
|
||||
def __init__(self, weight: int, colour: str, size: int, beakType : str, birdType : BirdType) -> None:
|
||||
self.__weight = weight
|
||||
self.__colour = colour
|
||||
self.__size = size
|
||||
self.__beakType = beakType
|
||||
self.__birdType = birdType
|
||||
|
||||
@abstractmethod
|
||||
def makeSound(self) -> None:
|
||||
...
|
6
python_code/oop/SOLID/bird/BirdType.py
Normal file
6
python_code/oop/SOLID/bird/BirdType.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from enum import Enum
|
||||
|
||||
class BirdType(Enum):
|
||||
Eagle = 0
|
||||
Penguin = 1
|
||||
Parrot = 2
|
16
python_code/oop/SOLID/bird/Eagle.py
Normal file
16
python_code/oop/SOLID/bird/Eagle.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from Bird import *
|
||||
from BirdType import *
|
||||
from interfaces.FlyableInterface import *
|
||||
from interfaces.FlyingBehaviourInterface import *
|
||||
|
||||
class Eagle(Bird, FlyableInterface):
|
||||
__flyingBehaviour: FlyingBehaviourInterface = None
|
||||
def __init__(self, weight: int, colour: str, size: int, beakType: str, birdType: BirdType, flyingBehaviour: FlyingBehaviourInterface) -> None:
|
||||
super().__init__(weight, colour, size, beakType, birdType)
|
||||
self.__flyingBehaviour = flyingBehaviour
|
||||
|
||||
def fly(self) -> None:
|
||||
self.__flyingBehaviour.makeFly()
|
||||
|
||||
def makeSound(self) -> None:
|
||||
...
|
7
python_code/oop/SOLID/bird/FlappingBehaviour.py
Normal file
7
python_code/oop/SOLID/bird/FlappingBehaviour.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from Bird import *
|
||||
from BirdType import *
|
||||
from interfaces.FlyingBehaviourInterface import *
|
||||
|
||||
class FlappingBehaviour(FlyingBehaviourInterface):
|
||||
def makeFly(self) -> None:
|
||||
print("Flapping")
|
7
python_code/oop/SOLID/bird/GlidingBehaviour.py
Normal file
7
python_code/oop/SOLID/bird/GlidingBehaviour.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from Bird import *
|
||||
from BirdType import *
|
||||
from interfaces.FlyingBehaviourInterface import *
|
||||
|
||||
class GlidingBehaviour(FlyingBehaviourInterface):
|
||||
def makeFly(self) -> None:
|
||||
print("Gliding")
|
16
python_code/oop/SOLID/bird/Parrot.py
Normal file
16
python_code/oop/SOLID/bird/Parrot.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from Bird import *
|
||||
from BirdType import *
|
||||
from interfaces.FlyableInterface import *
|
||||
from interfaces.FlyingBehaviourInterface import *
|
||||
|
||||
class Parrot(Bird, FlyableInterface):
|
||||
__flyingBehaviour: FlyingBehaviourInterface = None
|
||||
def __init__(self, weight: int, colour: str, size: int, beakType: str, birdType: BirdType, flyingBehaviour: FlyingBehaviourInterface) -> None:
|
||||
super().__init__(weight, colour, size, beakType, birdType)
|
||||
self.__flyingBehaviour = flyingBehaviour
|
||||
|
||||
def fly(self) -> None:
|
||||
self.__flyingBehaviour.makeFly()
|
||||
|
||||
def makeSound(self) -> None:
|
||||
...
|
14
python_code/oop/SOLID/bird/Penguin.py
Normal file
14
python_code/oop/SOLID/bird/Penguin.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Bird import *
|
||||
from BirdType import *
|
||||
from interfaces.SwimmableInterface import *
|
||||
from interfaces.FlyingBehaviourInterface import *
|
||||
|
||||
class Penguin(Bird, SwimmableInterface):
|
||||
def __init__(self, weight: int, colour: str, size: int, beakType: str, birdType: BirdType) -> None:
|
||||
super().__init__(weight, colour, size, beakType, birdType)
|
||||
|
||||
def fly(self) -> None:
|
||||
self.__flyingBehaviour.makeFly()
|
||||
|
||||
def makeSound(self) -> None:
|
||||
...
|
20
python_code/oop/SOLID/bird/Runner.py
Normal file
20
python_code/oop/SOLID/bird/Runner.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from distutils.ccompiler import gen_lib_options
|
||||
from Parrot import *
|
||||
from Eagle import *
|
||||
from Penguin import *
|
||||
from BirdType import *
|
||||
from interfaces.FlyableInterface import *
|
||||
from interfaces.SwimmableInterface import *
|
||||
from FlappingBehaviour import *
|
||||
from GlidingBehaviour import *
|
||||
|
||||
#import FlappingBehaviour gives error bcoz bird is package
|
||||
|
||||
parrot = Parrot(10, "Green", "Small", "Sharp", BirdType.Parrot, FlappingBehaviour())
|
||||
parrot.fly()
|
||||
|
||||
eagle = Eagle(20, "Brown", "Medium", "Sharp", BirdType.Eagle, GlidingBehaviour())
|
||||
eagle.fly()
|
||||
|
||||
penguin = Penguin(30, "Black", "Large", "Sharp", BirdType.Penguin)
|
||||
penguin.makeSound()
|
@@ -0,0 +1,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
class FlyableInterface(ABC):
|
||||
@abstractmethod
|
||||
def fly() -> None:
|
||||
...
|
@@ -0,0 +1,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
class FlyingBehaviourInterface(ABC):
|
||||
@abstractmethod
|
||||
def makeFly() -> None:
|
||||
...
|
@@ -0,0 +1,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
class SwimmableInterface:
|
||||
@abstractmethod
|
||||
def swim() -> None:
|
||||
...
|
0
python_code/oop/SOLID/bird/interfaces/__init__.py
Normal file
0
python_code/oop/SOLID/bird/interfaces/__init__.py
Normal file
Reference in New Issue
Block a user