Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I have a set of customized controls. E.g. they extend "RadioButton", "TextBox" and "CheckBox". Now I have added a couple of methods that these controls have in common (same implementation, too). Since they (my customized controls) can only inherit one type I wanted to put these common methods into an interface.

 

That way I would still have to copy the methods' body into every control but that would at least guarantee that these controls implement the common methods.

 

Now the problem:

Some of the common methods are private or protected or even have the override modifier but my interface tells me it wont let me use these :(

 

Should I just delete the interface and copy the methods to each control - not letting anyone know that they have these methods in common?

 

Or is there a chance for my interface to survive?

 

edit: "Explicit interface member implementation" doesn't help either...

Edited by Malfunction
Debug me...
  • Administrators
Posted

Interfaces by definition contain public functionality, they are designed to provide a consistant public interface to a series of components. Basically you can't put protected or private members into and interface.

However if your controls are in a single classlibrary you could mark the interface as being internal (friend in vb) and in each of the classes mark their implementation as also being internal. This way the interface can be used within the DLL but not from outside the DLL.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • *Experts*
Posted

I'd second Plausably's solution. If you just used the same named method names in each class, but not through an interface, then you lose the ability to cast an instnace of your control to the interface and call one of your new methods. Obviously that's only a benefit if you need that functionality, but I would think you would want it at some point.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

You need not copy the functionality.

 

You can programm a common HelperClass that is called by all classes.

 

Public Class A implements IX

Private _IXHelper as new IXHelper

Private Sub Soso (ByVal jaja as string)
 _UXHelper.Soso(jaja)
End sub

Public Sub Dada (ByVal nene as string) implements IX.Dada
  nene = someLocalPreprocessing (nene)
 _UXHelper.Dada(nene)
End sub

End Class

Public Class B implements IX

Private _IXHelper as new IXHelper

Private Sub Soso (ByVal jaja as string)
 _UXHelper.Soso(jaja)
End sub

Public Sub Dada (ByVal nene as string) implements IX.Dada
  nene = someOtherStuff (nene)
 _UXHelper.Dada(nene)
End sub

End Class

.nerd
Posted
Just because an interface is public doesn't mean you have to implement it publicly. Implementing the interface privately is actually better. If you make every method implemented in private, you can no longer access specific methods directly. You have to use a reference to the interface. :p

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

  • Leaders
Posted

you can access Private members still if you implement as Private in many cases by specifying the BindingFlags in a way like this ...

Reflection.BindingFlags.NonPublic [color=Blue]Or[/color] Reflection.BindingFlags.Instance

Posted (edited)
I knew it! at least I tried! :D Edited by DR00ME

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Posted

Uh.

I didn't have to tackle that problem.

 

Can you add the event handlers by code ?

 

 

Public Class malFunctionsTextBox
Inherits TextBox

Private _mF as new mFHelper

Private Sub New()
 Mybase.New
 AddHandler me.OnClick, AddressOf _mF.Click
End Sub

End Class

.nerd

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...