All Questions
Tagged with python object-oriented
156 questions
0
votes
0
answers
32
views
API design for precomputation cache [closed]
In my numeric code library I have a function totient_sum that depends on an expensive one-time precomputation totsum_range = [...], then different calls to totient_sum(n) are quick. There are several ...
0
votes
1
answer
258
views
Separation of concerns between business layer, data layer and presentation layer without losing information
I'm developing an api in Fast API using sqlalchemy to manage my ORM classes and operations with the database.
I'm dealing with some design decisions to have my classes as little coupled as possible ...
-2
votes
1
answer
295
views
Defining functions inside vs outside a class
Say I have a class with a function do_thing that is comprised of multiple steps, which themselves segregate into functions (first_process and second_process). At what point would this be considered ...
2
votes
1
answer
146
views
Refactoring Processor classes
I am writing some python 3 bioinformatics software and was wondering about the best way to write it in an OOP format. I am pretty sure a lot of my classes are violating the SRP principle, but I'm not ...
-3
votes
2
answers
278
views
Polymorphism with variable default argument count
I'm in the process of writing a library in Python, and I've run into a design problem concerning the use of polymorphism.
I have an ABC with abstract method 'foo':
class A(ABC):
@abstractmethod
...
2
votes
1
answer
1k
views
In Python when is absolutely preferable to use a class instead of a module?
Python is the language I use most in this period.
My background in Java
Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and ...
2
votes
2
answers
2k
views
Why access the attributes of a Python class by reference?
Attribute references and instantiation
In this link, that is part of the official Python documentation, I have found the following information:
Class objects support two kinds of operations: ...
0
votes
1
answer
853
views
Abstract base classes and mix-ins in python
In the python docs, I read this about the ABC (abstract base class) meta class:
Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class.
I don't come ...
1
vote
3
answers
988
views
Storing multiple instances on a Singleton?
RefactoringGuru's example Singleton in Python has an _instances dictionary field
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls....
3
votes
3
answers
315
views
Referencing transient class attributes
I've just started dipping my feet into OOP.
Is it considered bad practice to have classes that reference attributes that depend on another function being called and thus may not exist (version 1)? I'...
0
votes
1
answer
940
views
Dependency Injection for dynamic objects
I am learning about Dependency Injection and I have been recently implementing the following classes for an app that executes commands over ssh using Python. I am confused about whether I am using it ...
-1
votes
1
answer
3k
views
Calling helper functions in a Python `__init__` function
Problem
I am currently working with a class that necessarily has a very complicated initialization function (>350 lines of code) given that many computations and attributes need to be performed and ...
1
vote
1
answer
632
views
What to name class that applies methods of another class?
This is a pretty vague question, but, sometimes, I'm not very good at naming specific tasks, but I know it's very important and I don't want to name it something ungood.
I have the following file ...
0
votes
1
answer
127
views
Correct way to deduplicate conditional statements [closed]
I'm facing with problem that in every function (with serves as service for endpoint) I need to check what is value of query parameter (mode). I need to check it on many callables, E.g.
def create(self,...
2
votes
3
answers
1k
views
Should classes with business logic inherit from a class with helper methods, or vise-versa?
I have a codebase where some classes contain both "essential" business logic, and "incidental" complexity. I am considering a refactor where I leverage inheritance to improve the ...