A special type of subroutine called at the creation of an object.
0
votes
1answer
36 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 ...
-4
votes
2answers
78 views
Is the Copy-Swap Idiom implemented here correctly? [closed]
Is the Copy-Swap Idiom implemented here correctly?
...
0
votes
1answer
121 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
81 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
749 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 ...
3
votes
2answers
77 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
246 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
75 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
62 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
328 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
49 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
109 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 ...
5
votes
1answer
113 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
80 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
155 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 ...
1
vote
1answer
84 views
1
vote
3answers
59 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
63 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
65 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
91 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
281 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 ...
5
votes
3answers
280 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
102 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
632 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 ...
6
votes
3answers
626 views
Count PDF pages in constructor
I have an object that represents a PDF file. In the constructor, I pull out various information about the file name and make it available via properties:
...
7
votes
2answers
314 views
Should I set a license in the constructor or a static constructor?
We are using the Aspose PDF library to work with PDF files. Aspose requires the license to be set once per process. Accordingly, I have created the following common static method that sets the ...
4
votes
2answers
241 views
Exercising in copy constructors and assignment operators
I've just created an implementation of array to train myself in copy constructors, assignment operators, and exception safety. Please look at this code and tell me what is wrong here.
...
4
votes
1answer
53 views
Zip-like construction of objects from parameter collections
This little function can make object creation much easier.
Sometimes you need to switch between representing your data as objects vs. having the members in separate containers.
Example:
...
18
votes
5answers
813 views
When a constructor calls a helper function, should the helper mutate the object or return part of the object?
I have a private method that is called from the constructor to instantiate a bunch of objects.
I can do it two ways.
...
7
votes
2answers
739 views
What is the advantage/disadvantage of using default initializer for private fields?
Let's compare the following code:
1)
...
7
votes
2answers
367 views
Long constructors, inheritance, class method constructors
My class takes functions as a parameter. There are 6 of them, along with numerous other parameters. Almost all of the fields have default values.
It also has a class method that creates an instance ...
1
vote
1answer
53 views
Framework constructor
I'm working on my framework constructor. First I tried to look into jQuery and understand it, but it's so out of my league. Instead I googled and put this code together. Though there aren't many posts ...
2
votes
2answers
66 views
Making this login javascript code more organized and more competent?
I have this basic javascript that using a constructor, validates the form where the login fields cant be empty. All this WITHOUT using any js libraries. So far I have come up with this...
...
1
vote
2answers
116 views
1
vote
3answers
174 views
Review of three constructors for a String class
I have the following declaration in my String.h file:
private:
char* nstring;
int nlength;
};
The following are three constructors I've implemented in ...
3
votes
4answers
142 views
Reference type and constructors [closed]
Code in Java but should be readable also for c#...
Let's assume I have a class with some reference types. Example:
...
0
votes
1answer
133 views
Cleaning up PHP object constructors
I have this annoying problem in PHP with faking overloading constructors. I understand the concept, but the code I produce feels kind of ugly. It isn't a lot of code, just bad code. Any ideas on how ...
1
vote
2answers
80 views
Write a class with some properties and indexed
Is there a better way to write it? I need the best way to write it. It is this principle? Please show me a better way
it breaks SRP?
...
1
vote
1answer
209 views
__constructor mysqli variable options
I like the fact that I can create a class and have the connection details in one file if I need to update them and then pass them to the method I create in the class that defines my specific use of ...
4
votes
2answers
177 views
1
vote
2answers
1k views
JavaFX design writes to static field from constructor
In JavaFX, the lifecycle of an Application is quite different than Swing. Your constructor must take no arguments so that the ...
3
votes
2answers
2k views
Is this a correct way to write a convenience constructor?
I was reading more about the instancetype on Stack Overflow and now my question is:
For every convenience constructor that I write, do I need to have the ...
1
vote
1answer
123 views
Dynamic object creation in Python
I want to abstract away differences between zipfile and rarfile modules. In my code i want to call ZipFile or RarFile ...
3
votes
2answers
78 views
Changing the state of another entity into the constructor method
I have a Clock class who inherites from pyglet.clock.Clock and behaves like a Singleton.
Into the constructor method I have the following line:
...
1
vote
1answer
165 views
Java constructor should use setter?
I have a simple Java model Class called Person which have a constructor that receives a JSONObject. In that constructor I get the values from the JSONObject and put in my instance variables. This is ...
2
votes
3answers
209 views
Logic for an init function in email parser
I am writing an email parser and cannot decide how much logic should be included in the __init__ function. I know that a constructor should make the object ready ...
5
votes
3answers
450 views
Calling functions (or invoking methods) in constructor
I had written something like the following,
...
3
votes
3answers
2k views
Self populating view models
So I have a view model (asp.net mcv 3 app) that when instantiated with a particular parameter, populates it's properties via a couple of calls to a web service in it's constructor.
...
8
votes
1answer
3k views
Constructors and inheritance in Groovy
I am new to Groovy and I am having a little problem with constructors of subclasses. Basically, I have a base abstract class like
...
2
votes
1answer
123 views
Assign local-variables in constructor
How to make this code in constructor more DRY?
Is there some more concise way to assign variables passed through object?
...