multiple-constructors

C# string insertions confused with optional parameters

I'm fairly new to C#, and trying to figure out string insertions (i.e. "some {0} string", toInsert), and ran across a problem I wasn't expecting... In the case where you have two constructors: public MyClass(String arg1) { ... } public MyClass(String arg1, String arg2) { ... } Is it possible for me to use the first constructor with ...

Best way to do multiple constructors in PHP

You can't put two __construct functions with unique argument signatures in a PHP class. I'd like to do this: class Student { protected $id; protected $name; // etc. public function __construct($id){ $this->id = $id; // other members are still uninitialized } public function __construct($row_from_databas...

Calling another constructor from a constructor in PHP

I want a few constructors defined in a PHP class. However, my code for the constructors is currently very similar. I would rather not repeat code if possible. Is there a way to call other constructors from within one constructor in a php class? Is there a way to have multiple constructors in a PHP class? function __construct($service, $...

Which is better Java programming practice: stacking enums and enum constructors, or subclassing?

Hi folks, Given a finite number of items which differ in kind, is it better to represent them with stacked enums and enum constructors, or to subclass them? Or is there a better approach altogether? To give you some context, in my small RPG program (which ironically is supposed to be simple), a character has different kinds of items in...

C# - Adding to an existing (generated) constructor

I have a constructor that is in generated code. I don't want to change the generated code (cause it would get overwritten when I regenerate), but I need to add some functionality to the constructor. Here is some example code: // Generated file public partial class MyGeneratedClass { public MyGeneratedClass() { Does some g...

MEF Constructor Parameters with Multiple Constructors

Hi, i starting to use MEF, and i have a class with multiple constructors, like this: [Export(typeof(ifoo))] class foo : ifoo { void foo() { ... } [ImportingConstructor] void foo(object par1) { ... } } i am using catalog.ComposeExportedValue() when composing to suply the par1 value to 2nd constructor: ... catalog.ComposeEx...

In Scala, how can I subclass a Java class with multiple constructors?

Suppose I have a Java class with multiple constructors: class Base { Base(int arg1) {...}; Base(String arg2) {...}; Base(double arg3) {...}; } How can I extend it in Scala and still provide access to all three of Base's constructors? In Scala, a subclass can only call one of it's superclass's constructors. How can I work a...