473,385 Members | 2,003 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,385 software developers and data experts.

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 1398
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**************@TK2MSFTNGP15.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**************@TK2MSFTNGP15.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 "Overridable").

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(Me.mcClass1)
StartIt()
End Sub
Private Sub InitInterface(ByVal mailClientRefparam As
IWebmailclients.Iwebmail)
Me.mailClientRef = mailClientRefparam
End Sub

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

Brett
"W.G. Ryan eMVP" <Wi*********@gmail.com> wrote in message
news:eh**************@TK2MSFTNGP12.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**************@TK2MSFTNGP15.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*****************@newsfe2-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 "Overridable").

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**************@TK2MSFTNGP14.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
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.


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
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...
7
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...
3
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...
1
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...
62
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...
115
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...
43
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...
1
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.