Skip to main content

All Questions

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....
Michael Moreno's user avatar
0 votes
1 answer
527 views

Python: Function pipeline with multiple return/input values, or use OOP? Best Practices?

I have a 'processing' function and a 'serializing' function. Currently the processor returns 4 different types of data structures to be serialized in different ways. Looking for the best practise on ...
Jamal Rahman's user avatar
-1 votes
1 answer
210 views

Refactoring: Pythonic way of reducing the subclasses?

background: so, I am working on an NLP problem. where I need to extract different types of features based on different types of context from text documents. and I currently have a setup where there is ...
ultron's user avatar
  • 109
2 votes
1 answer
507 views

Converter implementation in Python: class versus module?

I've written a little library that uses the builtin ast library to convert between functions, docstrings, argparse .add_argument, classes, and [soon] more. Stubs look something like this, with ir ...
Samuel Marks's user avatar
4 votes
2 answers
4k views

What's wrong with using a Singleton?

I'm working on a Python application in which there are two Singleton classes: App and Configuration. The former seems straight forward, only ever instantiate one App instance; the latter seems ...
pstatix's user avatar
  • 1,047
1 vote
4 answers
884 views

Design pattern for a function class

I have been experimenting with the idea of function classes as explained in this article and Composition applied to function dependencies as described in the following questions: https://stackoverflow....
user32882's user avatar
  • 267
-3 votes
2 answers
141 views

Seeking appropriate design pattern(s) to describe most function-based mathematical problems

I have been looking for a good, general design pattern to implement simple mathematical structures where functions have the following properties: know which parameters they contain, parameters are "...
user32882's user avatar
  • 267
4 votes
2 answers
344 views

Does my class violate the Single Responsibility Principle in SOLID?

I want to ask: Whether the Role class violates Single Responsibility Principle in SOLID ? I think deleteAccount() is not belong to Role class but Role class is way to extend code in the future There ...
Nguyen Nguyen's user avatar
0 votes
2 answers
87 views

How to design classes of a self-driving machine, if I need a simulation?

Background: I'm working on a project with a self-driving machine with a tank-like control, somehting like: forward() left() right() stop() The code is running on a raspberry pi. The GPIO outputs are ...
tbzk's user avatar
  • 11
7 votes
2 answers
12k views

Design pattern for similar classes that require different implementations

Edited: Update is at the bottom There could be a common or best practice for this scenario, but I am unfamiliar with it. However, it could very easily be a matter of subjective opinion on how one ...
pstatix's user avatar
  • 1,047
2 votes
0 answers
69 views

How to interface with very badly written code in Python? [duplicate]

I have to extend some very badly written Python code (no documentation, very interdependent, barely any encapsulation, very static, everything hard-coded, etc..) and therefore do I obviously have to ...
PPP's user avatar
  • 29
0 votes
1 answer
63 views

Method grouping other methods of the same family and how to call any of these separately

Worse title ever but I don't really know how to describe my scenario in a line... So I have a method that wraps the calls of a many methods of the same nature. Once any of these methods have finished,...
dabadaba's user avatar
  • 2,266
0 votes
1 answer
71 views

Redesign factory to throw error on load time instead of on execution time

I am using a factory pattern to get objects that shouldn't be instantiated other than the factory class. These objects are of type ViolationType, which represent violations on a set of rule. Here is ...
dabadaba's user avatar
  • 2,266
1 vote
2 answers
12k views

Is it good practice to store instances within a class variable in Python?

I've come across two Stack Overflow posts that seem to offer conflicting answers: https://stackoverflow.com/questions/4831307/is-it-bad-to-store-all-instances-of-a-class-in-a-class-field https://...
atm's user avatar
  • 127
8 votes
3 answers
2k views

Refactoring of a client API for avoid duplicated code and unclear passage of parameters

I need to develop an API, the functions of the API are requests that call the service exposed by a server. Initially the API worked like this: class Server: def firstRequest(self, arg1, arg2): ...
k4ppa's user avatar
  • 227

15 30 50 per page