A special type of subroutine called at the creation of an object.

learn more… | top users | synonyms

0
votes
0answers
41 views

Class design for multiple interfaces of the same context [on hold]

So, there is a database table which store multiple account access information. ...
7
votes
1answer
112 views

Primitive Type Wrapper in C++

In C++, primitive types are treated differently than user-defined types. If you do not initialize them, their values are undefined in some cases. This is an easy mistake to make. I wanted to make a ...
4
votes
1answer
50 views

Class decorator in Python to set variables for the constructor

I personally don't like the boilerplate of most __init__ methods: self.a = a self.b = b ... So I thought this would be a nice ...
3
votes
0answers
62 views

2d game enemy entities factories, probably in need of refactoring

So I'm making a 2d shoot'em up game as a way of learning canvas, and larger-scale programming than what I'm accustomed to. I'm a purely front-end web dev, I can't say I'm very experienced in this. ...
1
vote
1answer
56 views

Inheritance and small number of parameters

Uncle Bob in his Clean Code says: So all the same rules apply. Functions that take variable arguments can be monads, dyads, or even triads. But it would be a mistake to give them more ...
2
votes
1answer
75 views

Java member method initialization pattern

To avoid the overridable method call in constructor dilemma this approache delegate the variables initialization and calls to overridable methods to a member method that return reference to the ...
1
vote
0answers
29 views

Throw exception in Spring when loading a file

I have this following piece of code: ...
4
votes
1answer
66 views

Python 3 class constructor

I have implemented a metaclass in Python 3 that, apart from the usual instance constructor (i.e. __init__), enables you to define a class constructor (as a class ...
0
votes
1answer
94 views

C++ lazy constructor

I'm implementing a lazy constructor in C++. The goal is that for a type T, lazy<T>(args...) returns a callable object ...
2
votes
1answer
98 views

C# data class with public auto-implemented properties with constructor that specifies each

I have a dll and an executable which both deal in configuring certain things for a much broader software solution, and the code below in particular is directly meant for database configuration. (Here ...
3
votes
2answers
53 views

A PHP MVC controller to display a form and add an item to the database

I am creating a controller that will display a form and once the form has been submitted to store the item in the database. After the item has been stored the user will be redirected back to the main ...
2
votes
1answer
69 views

Emulating constructor overloading in Typescript

I'm writing a Matrix class, and I want to be able to construct a Matrix in two ways: Supply a 2D array that the Matrix can use internally Supply the dimensions of the Matrix, and the value to fill ...
5
votes
3answers
530 views

Parsing a complex number using regular expressions

Requirements were to create a constructor for a complex number, that receives a string. For example: \$3+5i\$. The regex extracts positive or negative numbers from the string with optional decimal. ...
1
vote
1answer
48 views

Establishing parameters for a sales report, with default boolean and date values

The idea is that I am getting the params from a GET request in the form of a Hash (symbol→str) and I want to transform them into dates and booleans. For that reason,...
3
votes
2answers
142 views

Dynamic class instancing (with conditional parameters and methods) based on a dictionary

In a RPG game I'm developing, after building a base Weapon class, instead of having many subclasses of Weapon, I want the ...
15
votes
6answers
2k views

Constructors for a class to represent a price in € or $

I'm using a method to make initialize the attributes of my objects, and this method is called from both constructor. What it does is, if no correct currency has been passed, choose € by default. I'm ...
3
votes
2answers
187 views

Follow up - Creating Inheritance hierarchy using function constructor

In continuation with this question, Animal class has four fields: name sound ...
8
votes
1answer
122 views

Creating Inheritance hierarchy using function constructor

Problem statement You need to create the Animal base class having four fields: a. name b. ...
10
votes
1answer
91 views

A classy wine collection - Construction vs. Initialization

The following is for a chapter exercise in C++ Primer Plus, 6/e by Stephen Prata, for the first part of Chapter 14 which deals with code reuse through composition. The problem is to implement a ...
1
vote
2answers
87 views

Reducing code complexity for UsergridClient constructor

I'm initializing a class in JavaScript with a bunch of complex property checks. Codacy is showing that this is bad design and recommends reducing cyclomatic complexity. I'm at a loss for how to ...
3
votes
2answers
253 views

Dynamically creating elements with an object constructor

Just experimenting with various Javascript techniques and was wondering if the code below is valid and if there are any disadvantages to using this technique to create html tags from JS object ...
5
votes
6answers
174 views

__repr__ for a binary tree whose constructor has default arguments

I recently have been working on a BinaryTree class, and looked into creating a proper __repr__ which when eval'ed would recreate ...
3
votes
1answer
94 views

Constructing NewsArticle objects from a database table

This class seems to be able to represent the data stored in any possible database table: ...
8
votes
2answers
405 views

Declaration of bloatedness: the class that knew too much?

I've already expressed concerns about this type's constructor, and I've sort-of* implemented the changes suggested in the answers I got there. Recently I added even more parameters to that ...
2
votes
1answer
35 views

In a Content Pane mouse movements are logged and shown

I was trying to learn to develop plug-ins in Eclipse and after following the tutorial provided with Eclipse, tried to expand the code by writing a short Java class to track and display mouse movements ...
0
votes
1answer
78 views

YUIDoc syntax for optionally static constructor

In JavaScript, I wrote a class that can be optionally instantiated with the new keyword, but can also be called statically as well. What is the best way to ...
-3
votes
2answers
197 views

Is the Copy-Swap Idiom implemented here correctly? [closed]

Is the Copy-Swap Idiom implemented here correctly? ...
0
votes
1answer
292 views

Rule of 5 - C++11 [closed]

Source/Context: What is the copy-and-swap idiom? Rule-of-Three becomes Rule-of-Five with C++11? The C++ Programming Language 4th Edition June 2013 - Section 17.1 Introduction 483 ...
2
votes
1answer
100 views

Book constructor pattern

I am learning how to do object-orientated programming in JS. In particular, I am learning about the constructor pattern. In an attempt to exercise what I have been learning, I made this: ...
7
votes
4answers
6k views

Kelvin-Fahrenheit-Celsius temperature converter

I am curious if it would ever be in good practice to omit constructor definitions from a class. Here, the intention of the Temperature class is to simply convert between one temperature scale to ...
4
votes
2answers
392 views

Store open days and times

Currently I'm developing my business entities. I feel that the structure is a tad cumbersome. What I mean is that a store on a particular day can have different open and closing times. So it's not ...
1
vote
2answers
612 views

Utility class for an HttpURLConnection

I am creating a utility class to do an HttpURLConnection. I want to make this class generic as in I pass the URL and the POST params. It works with any range of ...
1
vote
1answer
2k views

A binary tree , its copy constructor and assignment operator

I implemented a binary tree in the following code. Its node's copy constructor and assignment operator should copy itself and all its descendents. Similarity a node's destructor should delete itself ...
3
votes
1answer
376 views

Making a copy constructor more flexible for ADT queue

I have constructed a copy constructor for an ADT queue. The copy constructor works fine. I would want to improve my code, but I don't really know how to shorten it to make it more flexible. ...
2
votes
4answers
405 views

Rule Of Three for a Coordinate class [closed]

I just recently got back into C++ and did a quick and simple exercise in the Rule of Three. The code for the copy constructor, overloaded assignment operator, and destructor follows below for my class ...
2
votes
1answer
53 views

Elegant way of processing an “options” parameter

In this constructor function I'm assigning everything to the proper variables. For the third parameter it accepts an options argument that contains the optional ...
3
votes
1answer
172 views

Instantiating a kind of NumPy array

I am creating a class object which must inherit from numpy ndarrays. I perform an isinstance check and an ...
6
votes
1answer
706 views

Applying the copy-swap idiom to humans and employees

I came across this post which explains the copy and swap idiom. However I could not find this idiom applied to classes that have base classes. Following is my attempt of a copy-swap idiom applied to ...
9
votes
1answer
100 views

Class that represents starting points and endpoints of a game

I am creating my first HTML5 game using JavaScript and Phaser framework. I have a class (or more accurately a prototype) called MajorPoint that represents the ...
2
votes
3answers
168 views

ADT for a TVM calculator

I wanted to get some criticism for the below ADT. This is just a basic ADT that will be fed into a TVM calculator. Main purpose is to have it initialized and correct for input errors. Full disclosure:...
1
vote
1answer
102 views

Constructing a UI to ask a list of questions

This code fragment from 2009: ...
1
vote
3answers
83 views

Initializing object by settings implemented as a class [closed]

Here is the story. We have the BankTerminalSettings class. It has many properties: ...
2
votes
0answers
159 views

handle drag and drop operations

I've come up with the following code to handle drag and drop operation. It's composed of a constructor function that returns an objects with methods to attach to event handlers. Notes about this ...
1
vote
1answer
429 views

Prompting the user for employment information

I have created a simple program in which the user is prompted for various details about their employment. In my Employee.java file, I have all the methods. Employee.java: ...
6
votes
2answers
146 views

File class and large constructor

I have some dispute with a colleague. I work with some REST-service, from which I get always same type data. ...
3
votes
3answers
316 views

Triggering editing mode for a form

I think that my code isn't perfect and I need a help to understand how to optimize it. In my application I have a main form and several forms for data editing. The user can: Add a new item Edit ...
8
votes
3answers
1k views

Parameterised Constructors

Finally, Parameterised Constructors are possible in VBA. Background: One rainy day, I came up with an idea: take a static class and expose one property as default (like it was done in the Reverse ...
7
votes
4answers
160 views

Avoid if/else in constructor - NavigableMap?

I have the following code, based on the input to the constructor I need to initialise some values which are wrapped in a simple POJO. These values are constant as you can see. However I don't like ...
3
votes
1answer
3k views

Dependency Injection into an Abstract Class

Me and another developer have recently forked and taken over an abandoned, open-source project. I have also been reading articles and watching videos by Misko Hevery. When I was reading through the ...
2
votes
1answer
231 views

Reading and storing values from JSON

I have a class ConfigFile that reads some values from a JSON using Boost and stores them in variables. Everything is done in the constructor: ...