473,563 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alternative to Interface?

I have created an interface with five properties and five methods. Five
classes are accessed through this interface and contain the implementation.
This setup works fine now. All the classes are encapsulated by the
interface.

If one of the classes requires a new method, this means I have to add this
method to the interface and all involved classes. My design breaksdown in
this case and becomes high maintenance. Is there a better approach to this
scenario or some way to overload the interface?

Thanks,
Brett
Nov 21 '05 #1
7 1417
Brett - why not just add the method to the class in question as opposed to
adding it to the interface?

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Brett" <no@spam.com> wrote in message
news:eA******** ******@TK2MSFTN GP15.phx.gbl...
I have created an interface with five properties and five methods. Five
classes are accessed through this interface and contain the implementation. This setup works fine now. All the classes are encapsulated by the
interface.

If one of the classes requires a new method, this means I have to add this
method to the interface and all involved classes. My design breaksdown in
this case and becomes high maintenance. Is there a better approach to this scenario or some way to overload the interface?

Thanks,
Brett

Nov 21 '05 #2
Bob
1. Why are you using an interface (is it necessary)?
2. Do *all* methods/properties have to be represented in an interface?
3. If so, must they all be in one?

Post your code (maybe attach a plain text file so the line breaks aren't
mangled). Maybe also include a breif functional description of what you need
to do.

Bob

"Brett" <no@spam.com> wrote in message
news:eA******** ******@TK2MSFTN GP15.phx.gbl...
I have created an interface with five properties and five methods. Five
classes are accessed through this interface and contain the implementation. This setup works fine now. All the classes are encapsulated by the
interface.

If one of the classes requires a new method, this means I have to add this
method to the interface and all involved classes. My design breaksdown in
this case and becomes high maintenance. Is there a better approach to this scenario or some way to overload the interface?

Thanks,
Brett

Nov 21 '05 #3
Brett wrote:
If one of the classes requires a new method, this means I have to add
this method to the interface and all involved classes. My design
breaksdown in this case and becomes high maintenance. Is there a
better approach to this scenario or some way to overload the
interface?


I examined the same problem and decided in the end to use inheritance
instead of interfaces to solve the problem.

I declared my base class as MustInherit, and into it I put all of the
properties and methods that I wanted my derived classes (plug-in DLLs in
this instance) to support. Some of the methods had to be implemented in the
derived classes, so I declared these as MustOverride. Others could be left
with either an empty implementation or could fall back to a default
implementation provided by the base class itself. These I declared
Overridable (after finally working out how to spell "Overridabl e").

This works very nicely; when I want to use one of the plug-ins, I can
declare an object with the type of the base class, and then set it to one of
the derived classes. This lets me early-bind to all the plug-in classes.

When I want to add a new property or method to the base class, as long as I
declare it as Overridable instead of MustOverride, everything continues to
work perfectly. You can therefore add as many new functions as you like,
providing they can fall back to the implementation in the base class when
the derived class doesn't override them.

--

(O) e n o n e
Nov 21 '05 #4
I use the interface to avoid switch statements. In the main form, I pass
the class name into a method. Inside that method are references using the
interface via the class name parameter passed in. There is much processing
done that makes use of data stored inside of these encapsulated classes. If
I had not done this, IFs or case statements would be required for explicit
references to each class. This shortens my code and keeps maintenance down.

For example, in the form, I do:

Private mailClientRef As IWebmailclients .Iwebmail

Private Sub btnSubmit_Click ()
InitInterface(M e.mcClass1)
StartIt()
End Sub
Private Sub InitInterface(B yVal mailClientRefpa ram As
IWebmailclients .Iwebmail)
Me.mailClientRe f = mailClientRefpa ram
End Sub

In the StartIt() method, I only need to reference mailClientRef.m ethodname
or property. That's why I use the interface.

Brett
"W.G. Ryan eMVP" <Wi*********@gm ail.com> wrote in message
news:eh******** ******@TK2MSFTN GP12.phx.gbl...
Brett - why not just add the method to the class in question as opposed to
adding it to the interface?

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Brett" <no@spam.com> wrote in message
news:eA******** ******@TK2MSFTN GP15.phx.gbl...
I have created an interface with five properties and five methods. Five
classes are accessed through this interface and contain the

implementation.
This setup works fine now. All the classes are encapsulated by the
interface.

If one of the classes requires a new method, this means I have to add
this
method to the interface and all involved classes. My design breaksdown
in
this case and becomes high maintenance. Is there a better approach to

this
scenario or some way to overload the interface?

Thanks,
Brett


Nov 21 '05 #5
"Brett" <no@spam.com> schrieb:
I have created an interface with five properties and five methods. Five
classes are accessed through this interface and contain the implementation.
This setup works fine now. All the classes are encapsulated by the
interface.

If one of the classes requires a new method, this means I have to add this
method to the interface and all involved classes. My design breaksdown in
this case and becomes high maintenance. Is there a better approach to
this scenario or some way to overload the interface?


Add the method to one of the classes only if it doesn't make sense for the
other classes. Place only those methods and properties in the interface
which are part of the interface's contract. In other words, only add
methods and properties to an interface which semantically belong to the
interface. Otherwise your code will be hard to understand and maintain.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

"Oenone" <oe****@nowhere .com> wrote in message
news:NH******** *********@newsf e2-win.ntli.net...
Brett wrote:
If one of the classes requires a new method, this means I have to add
this method to the interface and all involved classes. My design
breaksdown in this case and becomes high maintenance. Is there a
better approach to this scenario or some way to overload the
interface?
I examined the same problem and decided in the end to use inheritance
instead of interfaces to solve the problem.

I declared my base class as MustInherit, and into it I put all of the
properties and methods that I wanted my derived classes (plug-in DLLs in
this instance) to support. Some of the methods had to be implemented in
the
derived classes, so I declared these as MustOverride.


By the way, is MustOverride the same as Java's abstract? Or what is the VB
equivalent of abstract?
Others could be left
with either an empty implementation or could fall back to a default
implementation provided by the base class itself. These I declared
Overridable (after finally working out how to spell "Overridabl e").

This works very nicely; when I want to use one of the plug-ins, I can
declare an object with the type of the base class, and then set it to one
of
the derived classes. This lets me early-bind to all the plug-in classes.

When I want to add a new property or method to the base class, as long as
I
declare it as Overridable instead of MustOverride, everything continues to
work perfectly. You can therefore add as many new functions as you like,
providing they can fall back to the implementation in the base class when
the derived class doesn't override them.


Your approach is good. Actually, after rethinking my situation, I believe
the Interface is best. All of these classes should have exactly the same
methods and properties. Otherwise, my main form will have to make
decisions. If I do an override and certain classes fall back into the base,
I'll have to be sure it is handled correctly. That for every new addition
of a method.

I will instead encapsulate the function of any new method inside of an
existing method. If one class becomes a special case and requires a new
method, that functionality will instead be placed into an existing method.
This way, everything continues to work as before. If only there were a way
to encapsulate that specific piece of special case functionality.

If it is an across the board method addition, changes are required to the
interface, all encapsulated classes and the form. So an entire mod to the
app, which it should be.

Brett
Nov 21 '05 #7

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:e7******** ******@TK2MSFTN GP14.phx.gbl...
"Brett" <no@spam.com> schrieb:
I have created an interface with five properties and five methods. Five
classes are accessed through this interface and contain the
implementatio n. This setup works fine now. All the classes are
encapsulate d by the interface.

If one of the classes requires a new method, this means I have to add
this method to the interface and all involved classes. My design
breaksdown in this case and becomes high maintenance. Is there a better
approach to this scenario or some way to overload the interface?


Add the method to one of the classes only if it doesn't make sense for the
other classes. Place only those methods and properties in the interface
which are part of the interface's contract. In other words, only add
methods and properties to an interface which semantically belong to the
interface. Otherwise your code will be hard to understand and maintain.


You're right. All of these classes interacting with the interface
conceptually do the samething and look the same. Implementations differ
slightly but the special case may arise. I would like to take any special
case code and put it into a method. Is there a way to encapsulate it? I
can't put it into its own method because of the Interface. Is there another
way to encapsulate this?

Thanks,
Brett
Nov 21 '05 #8

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

Similar topics

5
2991
by: Aaron Ginn | last post by:
I'm investigating the feasibility of using Python instead of Visual Basic for a commercial software package that I'm planning on developing. Now I'm absolutely a Python zealot. I use it for most of my software development at work where I work in a Solaris environment. To me, Python is the perfect language for most applications in a UNIX...
7
2779
by: Henry Ludemann | last post by:
I've been writing an optparse alternative (using getopt) that is at a stage where I'd be interested in people's opinions. It allows you to easily creating command line interfaces to existing functions, using flags (which are optional) and arguments. It will automatically print a nicely formatted usage (eg: -h or --help), and easily &...
3
2374
by: Bruce | last post by:
Since DBlib is no longer the suggested method for connecting back to sql server from an Extended Stored Procedure, has anyone built any extended stored procedures that use other connection methods like OLEDB? Has anyone seen links to any sample extended stored procedures that use something other than db-lib? In particular I am interested in...
1
1818
by: f00sion | last post by:
I found a good tutorial of how to supply the objects without having the implementation files on the client. This was working great until I realized that I couldnt use any constructors with server activated objects, so I switched to client activated objects only to run into the next roadblock, doh! can't instantiate abstract classes... here is...
62
3319
by: christopher diggins | last post by:
Since nobody responded to my earlier post , I thought I would try to explain what I am doing a bit differently. When multiply inheriting pure virtual (abstract) base classes, a class obviously bloats quickly for each new vtable needed. Execution slows down considerably as well. You can work around this by using interfaces referemnces which...
115
14002
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i prefer a solution that (also) supports Windows. On the net I found a number of products that i looked at, but none of them gave me the impression...
43
6852
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's another story.) The data is written once and then read many times. Each primitive read requires unboxing. The data reads are critical to overall app...
1
2331
by: Hitchkas | last post by:
I posted this in PocketPC newsgroup with no response yet, hopefully somebody here has an answer. I have an application that runs locally on PocketPC. The user interface for this application is HTML with Javascript. The Javascript on the page instantiates an ActiveX control written in C++ ATL. The ActiveX does not have a visual...
5
4504
by: Phuff | last post by:
Hey all, I need some direction help. I have a switch case statement that is seemingly my only option right now, but its too large and not easy to maintain the code. Here goes... I have part descriptions (ie. 3/8" X ____" NYLON ALL-THREAD RODS...or ____" x ____" X ____" ____ WRAPPED MULLION) that I need to replace the blank lines on. I do...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.