A template for declaring a type of object.

learn more… | top users | synonyms (1)

-1
votes
0answers
130 views

Is it possible to turn an entire project to a single class file? [on hold]

I'm using Visual Studio 2013 Ultimate and I need to know if it is possible to turn an entire project (including settings, all classes, references...) to a single class (.cs file). you may be wondering ...
1
vote
1answer
49 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-...
-5
votes
0answers
50 views

How to define a 2D array of structures in a private of a class? [closed]

I want to define a 2D array of structures in a class in C++, how should I do it, here is an example approach for a struct tt class{ private: int a,b; tt yum[a][b]; }; Can this be done in some way? ...
1
vote
4answers
289 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
153 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 ...
8
votes
3answers
553 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
42 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
30 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
316 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
321 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
203 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
204 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
58 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 ...
1
vote
1answer
77 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
145 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
171 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
114 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
39 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
428 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
205 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
280 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
118 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
698 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
89 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
104 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
175 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
198 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
190 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
205 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
186 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
142 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
340 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
1k 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
140 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
96 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
2answers
102 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
90 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
188 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
136 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
291 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
57 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 ...
1
vote
4answers
9k views

What are the differences between class variables and instance variables in Java? [closed]

I'm very new to Java and want to be difference between class variables and instance variables. For example: class Bicycle { int cadence = 0; int speed = 0; int gear = 1; } How are ...
-2
votes
1answer
625 views

Good practice to hold Constants in their own file? [duplicate]

I've noticed some projects like to store constants in their own file, i.e constants used globally and in the main program loop might clutter the main file so perhaps they look to place them elsewhere ...
75
votes
13answers
8k views

Do objects in OOP have to represent an entity?

Does an object have to represent an entity? By an entity I mean something like a Product, Motor, a ParkingLot etc, a physical, or even a clear-cut non-physical conceptual object -- something that ...
2
votes
1answer
164 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. ...
0
votes
0answers
171 views

Class design for Token, TokenType and regex constants

For use in a lexer class a have a class Token which represents a token of a specific type and its value, while the types are defined by the enum TokenType in which every token holds its own regular ...