A template for declaring a type of object.
-1
votes
0answers
129 views
How can I share Variable values across classes [on hold]
My problem is the following, I have a class, let's call it BaseClass. and it have a property call NoOfWheels.
This BaseClass Value setting from SetWhellsValue() method in WindowUI class.
NoOfWheels ...
0
votes
1answer
54 views
Classes vs. modules in Python
Python has many modules (such as re) that perform a specific set of actions. You can call the functions of this module and get results, and the module as a whole has an idea behind it (in this case, ...
0
votes
1answer
63 views
Class vs Module - When classes are needed to be in module?
I am developing an application that has a lot of options like local database CRUD operations, file IO, web APIs calling, notifications, user preference settings, services, widgets etc.
At start it ...
-2
votes
0answers
19 views
Trying to understand what is contained in assertj-core file and how Java works
I've just started doing java exercises on exercism.io (great place if you haven't come across it already) and it uses gradle to run a test on the code you write.
The code that I wrote compiles and ...
1
vote
1answer
44 views
Creating widgets, setting/getting data from them - Pattern problem
Lets say I have a Widget class. I also have TextWidget, ComboWidget, ChoiceWidget classes that inherited from Widget class.
I create this widgets based on the situation. After creating the widget, I ...
1
vote
2answers
71 views
Modifying an existing class: should I extend it to a new class?
I'm working with a library (from an online source, not authored in-house) providing an interface as well as an implementation of it:
interface FooInterface {
// ...
}
class Foo implements ...
0
votes
3answers
222 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) :
...
1
vote
1answer
79 views
Does passing this as argument potentially cause exposure of invalid object state?
This question is based on two premises:
First: an object must always have valid state. It is discussed in various posts, too. http://stackoverflow.com/questions/22408804/should-a-c-object-always-be-...
0
votes
5answers
393 views
why can't class directly take arguments instead of using a constructor?
I referred this page for understanding about constructors in Java: http://www.javatpoint.com/constructor
So, I pretty much got it as in my own words:
constructor has no return value and is used ...
0
votes
2answers
161 views
Which pattern to use when I want to encapsulate large blocks of code?
I have a data structure, a large dictionary, that is mutated by several functions. Each function does a database call, some calculations and then changes the value of a key in the data structure. Each ...
9
votes
3answers
628 views
How should an `Employee` class be designed?
I am trying to create a program for managing employees. I cannot, however, figure out how to design the Employee class. My goal is to be able to create and manipulate employee data on the database ...
0
votes
1answer
46 views
Removing constraints of Java array
Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.
The class below aims to remove that constraint by allowing the class
user to specify the valid subscripts ...
0
votes
0answers
35 views
Choosing class names and relations for different user scopes
I am developing an online Order Management System using PHP in which I have some different behavioural scopes regarding the User class:
some user scope under which the chronological transactions are ...
4
votes
3answers
343 views
Why instantiate and initialize an object without saving it into a variable?
Sorry if I got the wording wrong in my title, but it would be easiest to provide an example in JavaFX
primaryStage.setScene(new Scene(grid, 300, 275));
Now from what I understand, this code is ...
9
votes
2answers
335 views
What does it mean to inject data (vs behaviour) in a class constructor, and why is that considered bad practice?
I am reading the book "Learning TypeScript" by Remo Jansen. In one section the author describes how to create a very simple proof-of-concept MVC framework including how to create the Model class and ...
1
vote
3answers
215 views
Define C++ class in one or more files
When creating a C++ class what is best practice>
Put the entire class definition and member functions in a header file
Put the class definition and function declarations in the header file and put ...
2
votes
0answers
219 views
Dictionary of dictionaries design in C#
My question: is there a canonical way of creating a dictionary of dictionaries and providing an outer/inner key pair? Is there a NugetPackage out there with an implementation?
In my code, I have now ...
0
votes
3answers
59 views
What do you call the two types of classes on a instance declaration
When you declare a new instance of a class, you do so in a lot of languages as:
MyClass obj = new MyClass();
The two MyClass mean subtly different things, often you will see:
IMyClass obj = new ...
0
votes
1answer
82 views
Fundamental difference between a static class and namespaced functions
I have been using "static" classes as a method to group functions with relating purposes under a common name that provides readability and maintainability to the code at the cost of performance and ...
1
vote
1answer
225 views
Using ninject in a class library
Looking for some help getting my head around ninject and DI.
Using the simple examples I've found online everything works nicely but trying to do something more complex is causing headaches.
I have ...
1
vote
1answer
228 views
Is calling the superclass constructor in a subclass really important?
The following piece of Python code uses a superclass solely as the repository of functions that one of more subclasses may draw from:
class Class(object):
''' A trivial repository for functions to be ...
-1
votes
1answer
150 views
What is the faster way to save and browse objects using vectors +/or maps? (c++)
I'm doing a object Garbage class using c++:
#include "Object.h"
class ObjectGarbage
{
public:
ObjectGarbage();
~ObjectGarbage();
void Call_All_Objects()
{
//(...
0
votes
1answer
121 views
How to call an unknown member function through an instance of a related class?
I have two classes. The first, called Game_Events, controls the objects and manages the general tasks. The second, called Button, is for one of those object instances.
The example below is wrong but ...
1
vote
2answers
40 views
Are Data defined into derived class saved when up-casting?
Let's say i have two class named Object (base class) and an actor class (derived class). The actor class uses physics so i need to implement it on the Actor class. But there are other derived class of ...
8
votes
5answers
481 views
Inheritance vs additional property with null value
For classes with optional fields, is it better to use inheritance or a nullable property? Consider this example:
class Book {
private String name;
}
class BookWithColor extends Book {
private ...
8
votes
4answers
213 views
When in your language classes are objects too, does the Liskov substitution principle apply to their interfaces?
According to Wikipedia the Liskov substitution principle states that
objects in a program should be replaceable with instances of their
subtypes without altering the correctness of that program
...
2
votes
3answers
156 views
Adding a function to class member
I'm not sure of the proper terminology here so I'm having trouble finding the answer to my question but here is what I want to achieve.
say I have
class ABC {
public:
int number;
};
and I ...
5
votes
6answers
288 views
Rule of thumb for deciding which class a method belongs to
For example, imagine a website which stores results about a certain sport or game, which has a typical "season" structure, such that there's both a Player and a Season class. To retrieve a player's ...
3
votes
1answer
123 views
Avoiding tightly coupled class definitions in Python for has-a relationships
I have the following code:
class Car(object):
def __init__(self, my_id):
self.my_id = my_id
self.color = color
self.brand = brand
self.get_color()
self....
9
votes
4answers
706 views
How to argue against this “completely public” mindset of business object class design
We're doing a lot of unit testing and refactoring of our business objects, and I seem to have very different opinions on class design than other peers.
An example class that I am not a fan of:
...
1
vote
1answer
97 views
Manual reload of Java classes static block
I have a static block which fetches data from database. This data is then being used by instance method. Since static block will be loaded once I fear that the data won't change in its lifetime.
How ...
1
vote
1answer
105 views
Is this the right way to use classes on this project?
Before any down voting or blaming, please bear in mind that this is my first "serious" Python project. Before this I have only coded a program that uses several Google API's to do stuff, and not much ...
1
vote
1answer
185 views
Function pointers vs. Derived classes
So I have a Signal class and a client class which manages a list of Signal objects.
The class provides a bunch of interfaces, one of them is an update()-function.
The update()-code is completely ...
5
votes
2answers
199 views
C++ class design with invariant
I've been pondering a really basic question about how far to take enforcing a class's invariant. Maybe that's worded badly, so as an example, let's say that I want to write a class which stores a ...
6
votes
2answers
195 views
Idiomatic way to write JavaScript class that maintains state and tells you when that state has changed
I am an experienced C++ developer but new to JavaScript. I want to write an ES6 JavaScript class that maintains state.
How do I tell when state has changed?
I can think of two ways to do this. One ...
2
votes
2answers
222 views
Where is the class itself stored at runtime to be used as a reference
In C# or Java we find that the objects are stored on heap and their reference vars are stored on stack. But at run time where is the class definition stored to be used as a template for creating ...
3
votes
6answers
195 views
If Class is to define attributes and methods, and Interface is to define (a set of) methods, then how to think of interface needing new attributes?
I thought a class is supposed to define, or give a blueprint, of attributes and methods for an object. And then, an interface is to provide a set of methods, as a contract for its clients. (and so a ...
1
vote
2answers
169 views
python - differences between reusable code vs. code for solving specific tasks
Reusable code (ex. libraries and frameworks) and code written to solve a specific task and not meant to be reused as a general tool (for example, code being used only by my 6 person team in a private ...
6
votes
4answers
349 views
Class design dilemma: Encapsulation vs Single Responsibility/Separation of Concerns
I'm working on a class that represents an object with multiple representations - one is an XML type representation used by an automatic ordering system, the other is a POJO-based representation used ...
0
votes
3answers
2k views
Using super keyword to access super class members
I have following questions about the super keyword in java:
I have a code below with classes:
A Extends no class contains integer variable i
B Extends class A contains integer variable i
C Extends ...
-1
votes
3answers
141 views
Python — Class and Object [closed]
I got a question that quite disturbs me a lot and I think it might help a lot if I had an answer to it. So I got this:
class Klasse1:
variable1 = "haha"
class Klasse2:
variable2 = "hoho"
...
2
votes
2answers
106 views
Advantages of extending the default Exception class
I've seen that it's possible to extend the default Exception class in PHP, enabling one to throw an IncorrectParameterTypeException exception, or a ValueOutOfRangeException exception (maybe these are ...
1
vote
3answers
112 views
What is the difference between proxy class and delegation in Python?
Wiki:
A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, ...
0
votes
1answer
92 views
Should I document expected call-sequences when call-order matters?
In dynamically and weakly-typed languages*, I often find myself with structures like the following pseudocode:
class Stateful:
# [ various datamembers / attributes / properties / fields / etc. ]
...
1
vote
3answers
195 views
Should I create a class for functions that uses of the database?
I have a PHP application which is pretty simple: It allows the user to create, edit and read a post. Basic stuff.
I have a Database class which handles the connection and the queries execution. The ...
0
votes
1answer
152 views
Function or class design in library API for efficient object reuse
I am currently building a library in C++11, where I spent a lot of time trying to design a good interface. After some small redesigns along the way, I've ended up with a design that I am happy with. ...
14
votes
4answers
3k views
Singleton or instantiate everytime I use? [duplicate]
I use a class that just extracts data from one known object, and distributes it to other known objects. No persistent configuration or such is needed in that class instance.
How should I decide ...
3
votes
1answer
68 views
CharSequence to represent a named object
I always followed the opinion to not abuse interfaces in case of decomposition.
Usually I only implement them if I am absolutely sure to have a "is-a"-relation and avoid implementing them if there is ...
2
votes
2answers
308 views
Is it OK to use (WTF) forms to validate against stuff from DB?
Form classes are intended (IMO) for submitted data against rules. For example: are passwords equal, is end date later than start date.
submitted data--->|Form|
Is it okay for Form classes to ...
2
votes
1answer
59 views
Should I be taking these as arguments or define them in a sub class?
So I am making a mario clone in pygame and I have a base class Character and two sub classes, Mario and Luigi. The methods that the Character class defines require a significant amount of attributes ...