Click here to Skip to main content
16,010,392 members
Home / Discussions / C#
   

C#

 
QuestionHow to know if there is a child control under a certain point ? Pin
Andres Coder11-Mar-04 17:06
Andres Coder11-Mar-04 17:06 
AnswerRe: How to know if there is a child control under a certain point ? Pin
OmegaSupreme12-Mar-04 2:06
OmegaSupreme12-Mar-04 2:06 
AnswerRe: How to know if there is a child control under a certain point ? Pin
John Fisher12-Mar-04 2:08
John Fisher12-Mar-04 2:08 
Generalc# opengl *.obj Pin
pertiu11-Mar-04 7:07
pertiu11-Mar-04 7:07 
GeneralRe: c# opengl *.obj Pin
Judah Gabriel Himango11-Mar-04 16:39
sponsorJudah Gabriel Himango11-Mar-04 16:39 
GeneralRe: c# opengl *.obj Pin
Heath Stewart12-Mar-04 3:32
protectorHeath Stewart12-Mar-04 3:32 
GeneralOOP - Multiple Inheritance Pin
MrEyes11-Mar-04 7:07
MrEyes11-Mar-04 7:07 
GeneralRe: OOP - Multiple Inheritance Pin
John Fisher11-Mar-04 16:24
John Fisher11-Mar-04 16:24 
Hi, I'll just post a quick answer. Browsing through the articles on CP, as well as looking for tutorials through google will get you much farther.

So, C# doesn't allow multiple inheritance of classes. But, it does allow multiple inheritance of interfaces. This combines to allow inheritance of 0 or 1 class and any number of interfaces.

When implementing multiple interfaces, you have two basic options. 1) Implement every interface member directly within your new class; or 2) Use implementation classes within your new class, and call these implementation members from the shell interface implementations within your new class.

Option 1 would look something like this:
public interface IWidgetA
{
    object wa
    {
        get;
        set;
    }
}
public interface IWidgetB
{
    object wb
    {
        get;
        set;
    }
}
public interface IWidgetC
{
    object wc
    {
        get;
        set;
    }
}

public class AllWidgets : IWidgetA, IWidgetB, IWidgetC
{
    protected object _wa;
    public object wa
    {
        get { return _wa; }
        set { _wa = value; }
    }

    protected object _wb;
    public object wb
    {
        get { return _wb; }
        set { _wb = value; }
    }

    protected object _wc;
    public object wc
    {
        get { return _wc; }
        set { _wc = value; }
    }
}


Option 2 would look something like this:
// Using the interface definitions from the previous section...
public class WidgetAImpl : IWidgetA
{
    protected object _wa;
    public object wa
    {
        get { return _wa; }
        set { _wa = value; }
    }
}
public class WidgetBImpl : IWidgetB
{
    protected object _wb;
    public object wb
    {
        get { return _wb; }
        set { _wb = value; }
    }
}
public class WidgetCImpl : IWidgetC
{
    protected object _wc;
    public object wc
    {
        get { return _wc; }
        set { _wc = value; }
    }
}

public class AllWidgets : IWidgetA, IWidgetB, IWidgetC
{
    protected WidgetAImpl;
    protected WidgetBImpl;
    protected WidgetCImpl;

    public object wa
    {
        get { return this.WidgetAImpl.wa; }
        set { this.WidgetAImpl.wa = value; }
    }

    public object wb
    {
        get { return this.WidgetBImpl.wb; }
        set { this.WidgetBImpl.wb = value; }
    }

    public object wc
    {
        get { return this.WidgetCImpl.wc; }
        set { this.WidgetCImpl.wc = value; }
    }

}


Note: I didn't intend for this to be directly compilation ready.

With this tiny little sample, the second method obviously is more work than the first. However, when you've got complicated or large routines, or large sets of data that every interface implementation will treat the same way, then the second option becomes more useful than the first. As with most programming tasks, when there is more than one way to do things, you need to weigh the options and see which is best.

I hope this helps you out!

John

"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

GeneralRe: OOP - Multiple Inheritance Pin
Michael Flanakin17-Mar-04 19:52
Michael Flanakin17-Mar-04 19:52 
Question Determine which users have a file locked? Pin
Member 59390311-Mar-04 6:54
Member 59390311-Mar-04 6:54 
AnswerRe: Determine which users have a file locked? Pin
Heath Stewart12-Mar-04 3:26
protectorHeath Stewart12-Mar-04 3:26 
GeneralRe: Determine which users have a file locked? Pin
Member 59390312-Mar-04 3:34
Member 59390312-Mar-04 3:34 
QuestionRe: Determine which users have a file locked? Pin
Martin#18-Jun-07 0:16
Martin#18-Jun-07 0:16 
Generalthis.ServiceName Pin
CraigSch11-Mar-04 6:42
CraigSch11-Mar-04 6:42 
GeneralRe: this.ServiceName Pin
John Fisher11-Mar-04 16:32
John Fisher11-Mar-04 16:32 
GeneralBindtoObject translation Issues Pin
Tristan Rhodes11-Mar-04 5:39
Tristan Rhodes11-Mar-04 5:39 
General- Solved. - ref GUID? Pin
Tristan Rhodes12-Mar-04 1:02
Tristan Rhodes12-Mar-04 1:02 
GeneralRe: - Solved. - ref GUID? Pin
Mike Dimmick12-Mar-04 2:25
Mike Dimmick12-Mar-04 2:25 
GeneralRe: - Solved. - ref GUID? Pin
Tristan Rhodes12-Mar-04 3:20
Tristan Rhodes12-Mar-04 3:20 
Generalfill a textbox from a dataset Pin
krisman11-Mar-04 4:43
krisman11-Mar-04 4:43 
GeneralRe: fill a textbox from a dataset Pin
Guinness4Strength11-Mar-04 4:47
Guinness4Strength11-Mar-04 4:47 
GeneralRe: fill a textbox from a dataset Pin
krisman11-Mar-04 5:28
krisman11-Mar-04 5:28 
GeneralRe: fill a textbox from a dataset Pin
partyganger11-Mar-04 5:56
partyganger11-Mar-04 5:56 
GeneralRe: fill a textbox from a dataset Pin
Edbert P11-Mar-04 16:22
Edbert P11-Mar-04 16:22 
GeneralRe: fill a textbox from a dataset Pin
krisman15-Mar-04 2:56
krisman15-Mar-04 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.