constructor-chaining

Strange (to me) constructor syntax can someone explain what this does?

public class PhotoList : ObservableCollection<ImageFile> { public PhotoList() { } **//this is the line that I dont recognise!!!!!!!!!!** public PhotoList(string path) : this(new DirectoryInfo(path)) { } public PhotoList(DirectoryInfo directory) { _directory = directory; Update(); } public...

What is C# code doing:

In the following code: public class A { public A():this(null){} public A(string b){/*code here*/} } What is the use of first constructor? ...

C# constructor chaining? (How to do it?)

Hi all, I know that this is supposedly a super simple question, but I've been struggling with the concept for some time now. My question is, how do you chain constructors in c#? I'm in my first OOP class, so I'm just learning. I don't understand how constructor chaining works or how to implement it, or even why it's better than just do...

How to chain these constructors (C#)?

Hi, I'm just getting the concept of chaining constructors down, but I can't figure out how to chain these two particular constructors together, so I would appreciate it if somebody could help me out. Thanks! Constructors // default constructor // purpose: initialize data members to zero // Parameters: none // returns: none public Li...

Help Using Constructors for this situation? (C#)

Hello there, I'm in my first OOP class and I really like it, but on this assignment, I'm not really sure what the best (most efficient, less code, etc.) way to use constructors in this situation? Preferably using constructor chaining. A little more info: I would like my default constructor to create & initialize all the objects shown...

Proper way to accomplish this construction using constructor chaining? (C#)

Hi, I have an assignment for my first OOP class, and I understand all of it including the following statement: You should create a class called ComplexNumber. This class will contain the real and imaginary parts of the complex number in private data members defined as doubles. Your class should contain a constructor that allows the...

Overloaded constructor chain

Original Question Consider the following scenario: public abstract class Foo { public string Name { get; set; } public Foo() { this.Name = string.Empty; } public Foo(string name) { this.Name = name; } } public class Bar : Foo { public int Amount { get; set; } public Bar() :...

Boo Constructor Chaining

In C# when I want to chain constructors together I'd do this... public class OperationMacro : GeneratePropertyMacro { public OperationMacro() : base("Operation") { //Whatever else I need to do... } } What is the equivalent syntax in Boo? ...

Is this a good or bad way to use constructor chaining? (... to allow for testing).

My motivation for chaining my class constructors here is so that I have a default constructor for mainstream use by my application and a second that allows me to inject a mock and a stub. It just seems a bit ugly 'new'-ing things in the ":this(...)" call and counter-intuitive calling a parametrized constructor from a default construct...

Chaining function calls jQuery style

Hi I've been playing around trying to recreate the way in which jQuery chains it's functions for it's "select" then "do" behaviour. Note: I don't want to chain functions with jQuery, I want to chain them like jQuery. So based on the jQuery code what I have so far is (doesn't work in IE): var x = function(string) { return new x.fn....

: this() As a constructor

I'm trying to get a better understanding of general practice... specifically deriving this() in a constructor. I understand that its less code, but I consider it less readable. Is it common/good practice to do it this way? Or is it better to write a second constructor that handles it specifically? public SomeOtherStuff(string rabble)...

Delphi: How to hide ancestor constructors?

Update: gutted the question with a simpler example, that isn't answered by the originally accepted answer Given the following class, and its ancestor: TComputer = class(TObject) public constructor Create(Teapot: string=''); end; TCellPhone = class(TComputer) public constructor Create(Cup: Integer); overload; virtual; co...

Delphi: Understanding constructors

i'm looking to understand virtual override overload reintroduce when applied to object constructors. Every time i randomly add keywords until the compiler shuts up - and (after 12 years of developing with Delphi) i'd rather know what i'm doing, rather than trying things randomly. Given a hypothetical set of objects: TComputer = cla...

Delphi: How to add a different constructor to a descendant?

Update: The example i originally had was kind of complex. Here's a simple 8 line example that explains everything in one code block. The following does not compile gives a warning: TComputer = class(TObject) public constructor Create(Cup: Integer); virtual; end; TCellPhone = class(TComputer) public constructor Create(Cup: Integ...

Delphi: When does reintroduce hide ancestors and when does it show them?

Today Recently on Stackoverflow i learned that: reintroduce is used to hide ancestor constructors reintroduce is used to show ancestor constructors i've been trying to make sense of it all, so here is a another, very specific question, supporting my main question dealing with constructors. Update: replaced the entire question: TC...

Delphi: Overridden virtual constructor descendant not being called by overload

Yet another in my series of questions regarding constructors in Delphi. i have a base class that has has the virtual constructor: TComputer = class(TObject) public constructor Create(Teapot: Integer); virtual; end; The constructor is virtual for the times that someone needs to call var computerClass: class of TComputer; co...

Understanding constructor visibility

Here's two simple classes, initially both have no keywords (virtual, overload, override, reintroduce): TComputer = class(TObject) public constructor Create(Teapot: Integer); end; TCellPhone = class(TComputer) public constructor Create(Teapot: Integer; Handle: string); end; i will represent these above defintions as the slightly...

Chaining constructors in JavaScript

Hello! I'm trying to implement some kind of class hierarchy in JavaScript. I think I understood the prototype chain, but I still have to sort out the constructor-chaining. Following David Flanagan's Definitive Guide, I wrote function DerivedClass() { BaseClass.apply(this, arguments); // chain constructors // do some initializa...