This file contains hidden or 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
class Foo: | |
def testOverideOrder(self): | |
print("Foo") | |
class Bar: | |
def testOverideOrder(self): | |
print("Bar") |
This file contains hidden or 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
iNum = 123 #will always be a number | |
sPaddingChar = "0" | |
iNumPads = 6 | |
#print the number with padded zeros, using % rather than .format | |
print ('%s' % (str(iNum).rjust(iNumPads, sPaddingChar))) |
This file contains hidden or 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
image: docker:latest | |
services: | |
- docker:dind | |
stages: | |
- test | |
- deploy | |
step-develop: | |
stage: test |
This file contains hidden or 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
CHAIR_FACTORY = ChairFactory().get_chair("SmallChair") | |
print(CHAIR_FACTORY.get_dimensions()) |
This file contains hidden or 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
# Asking for a `SmallChair` will pass the request to the `Chair Factory` | |
FURNITURE = FurnitureFactory.get_furniture("SmallChair") | |
print(f"{FURNITURE.__class__} : {FURNITURE.dimensions()}") | |
# prints <class 'chair_factory.SmallChair'> : {'width': 40, 'depth': 40, 'height': 40} | |
# And Asking for a `MediumTable` will pass the request to the `TableFactory` | |
FURNITURE = FurnitureFactory.get_furniture("MediumTable") | |
print(f"{FURNITURE.__class__} : {FURNITURE.dimensions()}") | |
# prints <class 'table_factory.MediumTable'> : {'width': 110, 'depth': 70, 'height': 60} |
This file contains hidden or 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 ABCMeta, abstractstaticmethod | |
from chair_factory import ChairFactory | |
from table_factory import TableFactory |
This file contains hidden or 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
class IFurnitureFactory(metaclass=ABCMeta): # pylint: disable=too-few-public-methods | |
"""Furniture Factory Interface""" | |
@abstractstaticmethod | |
def get_furniture(furniture): | |
"""The static funiture factory inteface method""" |
This file contains hidden or 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
class FurnitureFactory(IFurnitureFactory): # pylint: disable=too-few-public-methods | |
"""The Furniture Factory Concrete Class""" | |
@staticmethod | |
def get_furniture(furniture): | |
"""Static get_furniture method""" | |
try: | |
if furniture in ["SmallChair", "MediumChair", "BigChair"]: | |
return ChairFactory().get_chair(furniture) | |
if furniture in ["SmallTable", "MediumTable", "BigTable"]: |
This file contains hidden or 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
class ICommand(metaclass=ABCMeta): | |
"""The command interface, which all commands will implement""" | |
@abstractstaticmethod | |
def execute(): | |
"""The required execute method which all command obejcts will use""" | |
class SwitchOnCommand(ICommand): | |
"""A Command object, which implemets the ICommand interface""" |
This file contains hidden or 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
class Switch: | |
"""The Invoker Class""" | |
def __init__(self): | |
self._commands = {} | |
self._history = [] | |
OlderNewer