473,396 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Interface question

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
Nov 22 '05 #1
4 1010
Interfaces do not have constructors. They cannot be
instantiated. Only implementing classes do.

Tu-Thach
-----Original Message-----
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 defaultconstuctor but instead force them to use one constructor?

Thanx in advance
.

Nov 22 '05 #2
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/de...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.

Nov 22 '05 #3
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....

-----Original Message-----
Hello Kevin,

Thanks for your post. I agree with Tu-Thach that you need to implement aclass instead of an Interface. Please note that the Interfaces only definea set of properties, methods, and events without providing implementation.They are implemented by classes and structs. Please refer to the followingMSDN 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.
.

Nov 22 '05 #4
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.

Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
26
by: Marius Horak | last post by:
As in subject. Thanks MH
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
6
by: John Salerno | last post by:
I understand how they work (basically), but I think maybe the examples I'm reading are too elementary to really show their value. Here's one from Programming C#: #region Using directives ...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.