All Questions
18 questions
5
votes
6
answers
5k
views
How to modify object properties?
I've recently read a great article about unit testing. There was an example of a bad method which is not well designed. It looks like this
public static string GetTimeOfDay()
{
DateTime time = ...
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 ...
2
votes
1
answer
118
views
Is it a good software engineering practice to store libraries as attributes of objects?
Suppose I initialize a library, say, in python object -
#filename: file_A
import file_
class A():
def __init__(self):
self.pd = file_.pd
self.np = file_.np
And suppose the ...
1
vote
1
answer
198
views
Representing mathematical tree structures using software in a compact manner
In my work I frequently come across systems of interdependent equations. I have contrived a toy example as follows. The terminal values w, x, y and z are given:
e(y) = A+B
A(y) = x*log(y)+y^z
B(y) =...
2
votes
2
answers
4k
views
Module with globals or Class with attributes?
Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so:
STATE_VAR = 0
def ...
4
votes
4
answers
650
views
OOP - Is this data hiding?
I've been reading about data hiding and there seem to be slightly different definitions of it, so when trying to come up with a practical example, I'm not sure if I'm doing the right thing.
So far, I ...
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 ...
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,...
1
vote
2
answers
101
views
__init__ arguments differ from object attributes
Is the following class definition a good design?
class Myclass:
def __init__(self,num1,num2):
self.complicated_tree = __class__.object_creator(num1,num2)
@classmethod
def ...
0
votes
1
answer
2k
views
Create object inside a method
Let's say my object needs to use an API to communicate with a device. The API call that I need is Api.do_something().
What would be the best way to solve this assuming that I need to call it only ...
0
votes
3
answers
2k
views
When NOT to use a class / member variable?
I am trying to learn WHEN NOT to use:
classes
member variables
HERE IS THE CODE
access_point_detection_classes.py
from scapy.all import *
class Handler :
def __init__(self) :
self....
1
vote
3
answers
2k
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 ...
41
votes
6
answers
11k
views
Should I create a class if my function is complex and has a lot of variables?
This question is somewhat language-agnostic, but not completely, since Object Oriented Programming (OOP) is different in, for example, Java, which doesn't have first-class functions, than it is in ...
1
vote
2
answers
848
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 ...
14
votes
3
answers
41k
views
Python classes with only one instance: When to create a (single) class instance and when to work with the class instead?
Given a Python class which will be instantiated only once, i.e. there will be only one object of the class. I was wondering in which cases it makes sense to create a single class instance instead of ...