Category : solid-principles

I’m trying to refactor some classes using SOLID principles in python, and I have a question about how to mix SOLID with python typing. Suppose I have these classes: from asyncpg import Pool class PGQuery: async def execute(self, connection: Pool): raise NotImplementedError class PGQueryExecutor: def __init__(self, connection: Pool): self._connection = connection async def execute(self, query: ..

Read more

Let’s say we have a component class like this: class Component: def operation(self) -> str: return f"Performing operation" def another_operation(self) -> str: return f"Performing another operation" We then have a child of component that overrides both of its methods: class ChildComponent(Component): def operation(self) -> str: return f"Performing operation differently" def another_operation(self) -> str: return f"Performing ..

Read more

I have that Code example: from time import sleep import asyncio class bird: def __init__(self, sleeptime=1): self.var = sleeptime def wait_meep(self): sleep(self.var) print("Meep") def do_sth(self): print("Dop Dop Do do …") class bird_async: def __init__(self, sleeptime=1): self.var = sleeptime async def wait_meep(self): await asyncio.sleep(self.var) print("Meep") def do_sth(self): print("Dop Dop Do do …") As you can see, ..

Read more

I am not good at naming, I good at feeling. Suppose we have this hypothetical function: function computePowerAndPrintResult(int x){ print(x*x); } It screams already in the naming of the function ("And") that something wrong here and personally I never write code like this. Which principle is being violated here? Is it the single-responsibility principle? Source: ..

Read more