Interface question

  • Thread starter Thread starter Kevin Phifer
  • Start date Start date
K

Kevin Phifer

When defining a Interface, I don't seem to have the
ability to define a constructor. Is this possible?

If not, is there a way to keep people from using a default
constuctor but instead force them to use one constructor?

Thanx in advance
 
Interfaces do not have constructors. They cannot be
instantiated. Only implementing classes do.

Tu-Thach
 
Hello Kevin,

Thanks for your post. I agree with Tu-Thach that you need to implement a
class instead of an Interface. Please note that the Interfaces only define
a set of properties, methods, and events without providing implementation.
They are implemented by classes and structs. Please refer to the following
MSDN article for detailed information:

Interfaces Overview
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/
vaconinterfacesinvisualbasic70.asp

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanx for the responses,
What I ended up finding was that I could create a base
abstract class that implemented the constructor I wanted
and when inheriting from it, it would accept only that one
and wouldn't compile otherwise.
However, I was attempting this because I wanted to force
the way the class was loaded and new ones where created,
so what I relized was I could create static methods on the
base class. These static methods did nothing but throw an
exception, there by forcing those who comsumed my base
class to create new ones. This coupled with a private
constructor effectively allowed me to force a object
factory out of my base class. Does this make since?

Anyway, if there is a better way to go about this I would
love to know. Thanx again....
 
Hello Kevin,

Thanks for your information. I believe creating a base abstract class is a
good method to achieve your goal.

Please feel free to let me know if any further is needed.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top