object-construction

Why should I prefer to use member initialization list?

I'm partial to using member initialization lists with my constructors... but I've long since forgotten the reasons behind this... Do you use member initialization lists in your constructors? If so, why? If not, why not? ...

Using constructor without operator 'new'

Please help me to understand why the following code works: <script> var re = RegExp('\\ba\\b') ; alert(re.test('a')) ; alert(re.test('ab')) ; </script> In the first line there is no new operator. As far as I know, a contructor in JavaScript is a function that initialize objects created by the operator new and they are n...

Object construction/Forward function declaration ambiguity

Observation: the codes pasted below were tested only with GCC 4.4.1, and I'm only interested in them working with GCC. Hello, It wasn't for just a few times that I stumbled into an object construction statement that I didn't understand, and it was only today that I noticed what ambiguity was being introduced by it. I'll explain how to ...

Should I load my Java object's data on construction, or explicitly through a method call?

This is a design question. I'm trying to decide between 2 implementations. In order to properly explain this I need an example. So, for the sake of example: I have a class that generates a report about, let's say, certain Stock Market values on a specific day. I create a StockMarketReportGenerator object, passing it today's date, and i...

How do you construct an object without initializing it? (.net)

When you new an object in C# a few things must happen: memory for the object is created, and whatever other book-keeping CLR whats to do fields are initialized to default values the constructor is invoked Serialization frameworks seem to have some magical way to do 1 without doing 2 and 3. Or maybe it's not so magical after all. How ...

Create generic class with internal constructor

Is it possible to construct an object with its internal constructor within a generic method? public abstract class FooBase { } public class Foo : FooBase { internal Foo() { } } public static class FooFactory { public static TFooResult CreateFoo<TFooResult>() where TFooResult : FooBase, new() { return new TFooResult(...

Need a design pattern to remove enums and switch statement in object creation

Let's say I am creating a sports game, and in this game there are various positions a player can play, attack, defence, etc. So I start by creating a base class: public abstract class Position { public abstract string Name { get; } } and the subclasses... public class Defender : Position { public override string Name { get {...