1
vote
0answers
5 views

ORM Classes and Separation of Concerns

I am using Python's peewee ORM to map my relational database, but I'm noticing that my models are starting to get bloated and I also seem to be violating separation of concerns. For example, my User ...
0
votes
1answer
53 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 ...
1
vote
1answer
73 views

Pattern for subclass overload with different arguments

I'm in the process of writing an bidirectional, asynchronous socket server and server handler. The base handler class I'm working off of is as follows: class BaseAsyncSocketHandler: async def ...
0
votes
2answers
111 views

Python MVC-file-separation

I'm used to programming in Java, so my view of these things is quite Java based but I doubt this is the correct way of writing Python code. I found this https://stackoverflow.com/questions/106896/how-...
6
votes
1answer
176 views

In more canonical OO Python situations, what is the rule of thumb for default access modifiers?

Generally speaking in canonical OOP situations, the rule of thumb is to write your classes with the least access as necessary. i.e. only make public only what is necessary, make protected only what is ...
-1
votes
2answers
87 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://...
0
votes
0answers
82 views

Implementing ECB Pattern in MVC Pattern Framework

I am wondering how to implement a fully functional and legitimate ECB (Entity Control Boundary) pattern of design using a typical framework (Rails, Django, etc) that is centered around the MVC pattern....
3
votes
2answers
135 views

three overlapping project - how to organize

At the moment I am developing three scientific software projects (computer vision) in parallel in Python and scratching my head about organization, clean code and easy extensible/to maintain code. ...
1
vote
2answers
99 views

Critique on design principle and validity of such in general

I was hoping you could give some feedback on an idea I had for designing functions. I am trying to think of a unifying principle for choosing what functions should return. The specific project is ...
2
votes
2answers
57 views

Relating to design and runtime - is it better to parallelize smaller sub-tasks or bundled tasks?

I'm programming a small web scraper in python which I want to speed up by parallelizing things. The scraper is crawling URLs whereby a single URL can represent an 'item' or an 'index'. An index in ...
1
vote
2answers
115 views

How to complete a task in two seperate 'else' statements while maintaining DRY [duplicate]

What is the best way to implement the following code without having the same code duplicated in two different blocks, but while maintaining efficiency and readability? if (expression1): if (...
2
votes
1answer
718 views

Using singletons in Python (Django)

I was suggested to define a singleton in Python in the following way: class Controller: pass # ... controller = Controller() However, this way, controller cannot be replaced with a derived ...
0
votes
1answer
70 views

Error checking design question (python & MVC)

Which is better as a design perspective? An object that gets initialized and then checks to see if the parameters passed to it are valid before destroying itself (so in __init__) or Check to see if ...
0
votes
2answers
92 views

Creating instances of an ability when there are multiple different type of abilities

I'm creating an RPG game where a player has a set of skills, each of which he can level up to improve its effect. Here are two example skills: health: increase player's maximum health regeneration: ...
2
votes
4answers
222 views

Approach for refactoring a function that has lots of special braching

I am writing a function that operates slightly different depending on the data passed in. The common and unique code is mingled. I don't like what I have and am looking for a better way. Hopefully, ...
27
votes
9answers
3k views

Are there any design patterns that are possible only in dynamically typed languages like Python?

I've read a related question Are there any design patterns that are unnecessary in dynamic languages like Python? and remembered this quote on Wikiquote.org The wonderful thing about dynamic typing ...
1
vote
1answer
248 views

Is using __import__('module_name') an antipattern in Python?

I'm currently refactoring a Python 2 project which includes the ability to add or remove plugins, which are Python modules implementing a given API. The main app accesses add/remove/update hooks in ...
0
votes
1answer
110 views

How to make it clear I'm violating Command Query Separation

Command Query Separation is a useful principle, though it's not always ideal. Sometimes you need to run a process, which will result in useful data you need to return. My specific case is uploading a ...
5
votes
1answer
365 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): ...
1
vote
3answers
285 views

How To Extend Parent Methods in Children Classes?

There is a parent class with a method which many children use but many children extend the method, what is the best way to extend it without violating DRY? Here are my 2 current solutions: 1: The ...
5
votes
1answer
100 views

Enclosing main invocation of a function in an if

As a part of my school CS class, I am reading Python Programming by John Zelle. In the book, Zelle talks about surrounding the invocation of a main method with if <condition>: main() ...
7
votes
2answers
2k views

how to refactor many singletons

I have a medium-sized python program (~5000 lines of code), which I've built up over time, with no particular plan as I went ahead. The architecture I've ended up with consists of 5-6 large Singleton ...
6
votes
1answer
264 views

UI Design patterns for non-screen based project

I'm working on a small project coded in Python that uses a single button for input and a RGB LED as feedback, which responds to button presses and asynchronous events from the network. As the ...
1
vote
2answers
328 views

How should I structure these Python classes?

Base Class I have a class called Remote. This class represents a remote machine and has properties such as ip, hostname, username, and password, as well as methods for transferring files to/from the ...
2
votes
1answer
324 views

Could there be a use case for C# style auto-properties in Python

I've been doing a lot of work in C# recently (my primary language is Python) and I love that I can do something like public string MyProperty{ get; set; } Going back to Python I miss that sort of ...
0
votes
1answer
46 views

Accessing data in widget

Background I started to get involved in a project written in python and wxPython (for the GUI). My task is to debug and add a few features to the GUI. The widgets are organised mainly with sizers, ...
2
votes
1answer
273 views

What design patterns could be used here?

I'm trying to come up with a nice design (preferably pythonic) for the following use case. Say there's three services - A, B, C in multiple locations L1, L2, L3, etc. Each service provides ...
2
votes
1answer
217 views

Python Classes and Design Questions

What is the best way to design a class to see if an update occurs on a property? I have a whole bunch of classes, and current am going through a re-design of the python package I created. ...
1
vote
2answers
118 views

Efficient way to handle foreign keys

I am building a script that checks a large network of sites for invalid links. The idea is to flag links that continuously show as not available so that they can be cleaned by the administration team. ...
3
votes
1answer
217 views

Encapsulating mutable objects with special structure in Python

I am writing a library for working with special types of trees, called Foo trees. A Foo tree has very special structure. There some operations, called bar and baz, which only make sense on Foo trees. ...
1
vote
1answer
363 views

How would a modern website like Reddit divide up its website into Django apps? [closed]

Django uses apps to divide projects into manageable and reusable chunks. All examples in tutorials use polls or articles in unrelatable circumstances. In a modern example like Reddit (or even Amazon ...
4
votes
1answer
129 views

How should I represent composeable, associative computations to be repeatedly applied to units of data?

Spoiler My question is the following: Are there any design patterns for representing chainable functions that are for the problem described below? High-Level Decription of the Process I'm ...
1
vote
1answer
224 views

Should I couple these classes?

I am programming in Python. I have several complicated/hard-to-understand XML files that describe the structure of an election. I am trying to write a python wrapper that makes it easy to access this ...
0
votes
1answer
755 views

Best Practices For Temporary Scripts (Python)

I am running two separate programs which are similar enough that they share a lot of code. I run these programs often and after I evaluate the output. This is a very fluid process and everytime is ...
3
votes
1answer
349 views

Good practice for returns in Python

I was recently working on some prototype code in Python. The code worked great, then I realized that I needed a little more feedback from one of my functions so I changed the return statement from ...
2
votes
2answers
100 views

subclass reference to another subclass

Imagine I have the following code: class A: pass class B(A): pass class C(A): def __init__(self): self.b = B() Is the above code correct in terms of correct inheritance? I mean ...
1
vote
1answer
131 views

Adding new functionality to all of shelve.Shelf's subclasses in Python

In order to avoid the overhead associated with the shelve module's writeback option I'm interested in putting together a shelf class that only accepts hashable values, with hashability being a proxy ...
0
votes
1answer
182 views

Is the following example a strategy pattern?

In my problem I had lots of objects with slightly different behaviour, but identical attributes and methodes with identical interfaces. The objects variants were quite big in number, and I didn't want ...
2
votes
1answer
348 views

Python - Is this a bad strategy pattern?

I've got a Python project wherein a basic object is created and various different attributes are modified/given to it via what I thought was a good example of a strategy pattern. In this silly game ...
8
votes
3answers
3k views

Global request context - anti-pattern?

I was talking today to a colleague of mine about Python web frameworks and our impressions about them. I told him I think Flask having a global request smells badly and is an anti-pattern. The docs ...
0
votes
1answer
129 views

Pythonic design for controlling multiple devices through an I2C bus

I'm writing a piece of software in python that will communicate with a bunch of devices via an I2C bus. Each of these devices are going to need some sort of a module or class to handle the ...
3
votes
3answers
475 views

What are the advantages of dynamically binding a method to class instance? [closed]

I came across Instagram's API client written in Python. In their class InstagramAPI, they bind the methods to a function in bind.py. When called, the function returns an instance of the class ...
1
vote
2answers
4k views

Model-View-Controller — Where does a factory class go?

I'm working (slowly) on a small Flask project. One of my models is a class called Post, which is a lightweight namedtuple. Post objects are created by a PostFactory, because creating a Post involves ...
2
votes
4answers
507 views

How to elegantly work with a lot of print functions?

I'm working on a Python project that is executed on a terminal (or console) for which I am planning to implement a GUI. I did not major in CS so I really have no idea how to effectively design a ...
4
votes
1answer
3k views

How to design a composite pattern in Python?

The concept I'm programming an interface over pygame as a personal project, to make the creation of games easier for me. So far I managed to design an architecture that behaves like this : Objects ...
4
votes
1answer
3k views

How should I architect a personal schedule manager that runs 24/7? [closed]

I've developed an ADHD management system for myself that's attempting to change multiple habits at once. I know this is counter to conventional wisdom, but I've tried the conventional for years & ...
13
votes
2answers
2k views

Object oriented vs vector based programming

I am torn between object oriented and vector based design. I love the abilities, structure and safety that objects give to the whole architecture. But at the same time, speed is very important to me, ...
0
votes
3answers
716 views

Object design where hard-coded values are used to instantiate objects?

I'm creating the design for a browser bookmark merging program and I've ran into a design problem that I've seen before yet I've never come up with a good solution for it. So lets say I have a ...
6
votes
4answers
524 views

How to create different paths for users to take through the pages in my site?

I have a website where users are directed to go through a sequence of pages to perform a sequence of work tasks (transcribe a paragraph, answer a survey, interact with another user, etc). For short, ...
11
votes
4answers
6k views

Returning a boolean when success or failure is the sole concern

I often find myself returning a boolean from a method, that's used in multiple locations, in order to contain all the logic around that method in a single place. All the (internal) calling method ...