Adds python code (#7)

This commit is contained in:
Abhishek Singh Thakur
2022-10-13 19:54:41 +05:30
committed by GitHub
parent 8c24d0345a
commit 59d2d5acfb
19 changed files with 221 additions and 0 deletions

View 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:
...

View File

@@ -0,0 +1,6 @@
from enum import Enum
class BirdType(Enum):
Eagle = 0
Penguin = 1
Parrot = 2

View 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:
...

View File

@@ -0,0 +1,7 @@
from Bird import *
from BirdType import *
from interfaces.FlyingBehaviourInterface import *
class FlappingBehaviour(FlyingBehaviourInterface):
def makeFly(self) -> None:
print("Flapping")

View File

@@ -0,0 +1,7 @@
from Bird import *
from BirdType import *
from interfaces.FlyingBehaviourInterface import *
class GlidingBehaviour(FlyingBehaviourInterface):
def makeFly(self) -> None:
print("Gliding")

View 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:
...

View 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:
...

View 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()

View File

@@ -0,0 +1,6 @@
from abc import ABC, abstractmethod
class FlyableInterface(ABC):
@abstractmethod
def fly() -> None:
...

View File

@@ -0,0 +1,6 @@
from abc import ABC, abstractmethod
class FlyingBehaviourInterface(ABC):
@abstractmethod
def makeFly() -> None:
...

View File

@@ -0,0 +1,6 @@
from abc import ABC, abstractmethod
class SwimmableInterface:
@abstractmethod
def swim() -> None:
...