How? Object is a form and inherits as well

R

RubiconXing

Hi All

I am just learning C# and .NET please be patient with me :) I would
be very interested in how you approach the problem below:

I have a form (collects username and password information) and these
are presented as public properties. I also like this form to be
another object from a library of controls (call it ControlX) so I can
use that base functionality. (give it to a control container which
keeps a collection of them etc).

There is no multiple inheritance - so I can only inherit from the
system Form class or ControlX. ControlX does not seem to offer any
interfaces. Is it possible to inherit from ControlX and somehow
transparently imbed the form functionality in the class so that the
clase is a ControlX and is a Form? (or vice versa)

I suppose I could make a ControlX class and then have it internally
create and manage an instance of a separate Form class to display its
contents when asked. But then I'd have two separate clases maintain,
load and transfer data between. Is this really the way you would do
it? Is there a better way?

All opinions and advice gratefully received.

Cheers
-R
 
J

Joshua Flanagan

Based on the limited information of what you are trying to accomplish, I
would say your last suggestion is probably the best way to do it. It is
called "extension through composition", which is often preferred over
"extension through inheritance".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top