|
-
November 18th, 2009, 04:06 PM
#1
Empty Constructors
Is anyone else bothered by this as much as I am? I hate them, they look like such a waste. When you have a base class that your inheriting from and it requires some arguments via its constructor but your derived class does not require anything upon construction, your required to use the derived classes constructor as a middle-man who's sole purpose in life is to just pass the arguments to the base class constructor, leaving you with an empty derived class constructor body.
This to me is a tragedy:
Code:
public class Manager : Employee
{
public Manager(string name)
: base(name) { }
}
They drive me insane sometimes to the point where Ill think of something, anything, to pass to the derived constructor to assign to a field, or call a function, or something just to make it do something other than act as a middle-man. Anyone else have this "disorder"? haha
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
-
November 19th, 2009, 11:35 AM
#2
Re: Empty Constructors
How about creating an empty constructor in the base class, or
Code:
public class Manager : Employee
{
public Manager( )
: base( String.Empty ) { }
}
-
November 19th, 2009, 02:54 PM
#3
Re: Empty Constructors
I had thought about that, but the class I'm building requires the use of an EndPoint object. Since I'm using network resources I want to force the EndPoint to be passed when the object is constructed. I want to make it immutable and not have to expose it as a public property just so I can allow it to be set later.
I'm probably just going to have to review my code and see if I can fix it, or if I can't, its not a huge deal because the constructor in this case does actually have a little bit of work to do.
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
-
November 27th, 2009, 06:24 AM
#4
Re: Empty Constructors
 Originally Posted by RaleTheBlade
When you have a base class that your inheriting from and it requires some arguments via its constructor but your derived class does not require anything upon construction, your required to use the derived classes constructor as a middle-man who's sole purpose in life is to just pass the arguments to the base class constructor, leaving you with an empty derived class constructor body.
The constructor initialises the base class subobject. That makes it sound more useful than "the constructor is a middle-man whose sole purpose in life is to pass the arguments to the base class constructor" 
Besides, speaking from the point of view of C++, there is nothing wrong with having an empty constructor body. If it is feasible, I prefer to make the initialisation list do all the work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|