Click here to Skip to main content
12,820,118 members (22,042 online)
   

C#

 
GeneralRe: Manual Coding vs Code Generation Pin
PIEBALDconsult22-Nov-12 10:51
memberPIEBALDconsult22-Nov-12 10:51 
AnswerRe: Manual Coding vs Code Generation Pin
PIEBALDconsult21-Nov-12 5:00
memberPIEBALDconsult21-Nov-12 5:00 
QuestionDesign Question Pin
TheGermoz15-Nov-12 18:31
memberTheGermoz15-Nov-12 18:31 
AnswerRe: Design Question Pin
DaveyM6915-Nov-12 20:31
mentorDaveyM6915-Nov-12 20:31 
You should only use a base class where you want the exact same implementation in all derived classes.

A an interface is a contract (no implementation unlike an abstract class) I don't really see the problem. This works just fine:
public interface I1
{
    void A();
    void B();
}
public interface I2
{
    void A();
    void B();
    void C();
    void D();
}
public class ClassA : I1, I2
{
    public void A()
    { }
    public void B()
    { }
    public void C()
    { }
    public void D()
    { }
}

If you want differing implementations of A and B depending on whether usin I1 or I2 then use explicit declaration:
public class ClassA2 : I1, I2
{
    void I1.A()
    { }
    void I2.A()
    { }
    void I1.B()
    { }
    void I2.B()
    { }
    public void C()
    { }
    public void D()
    { }
}

You will now need to cast the instance to either I1 or I2 to have access to methods A or B, but you can mix it up and provide the default implementation:
public class ClassA2 : I1, I2
{
    public void A()
    {
        (this as I1).A();
    }
    public void B()
    {
        (this as I1).B();
    }
    void I1.A()
    { }
    void I2.A()
    { }
    void I1.B()
    { }
    void I2.B()
    { }
    public void C()
    { }
    public void D()
    { }
}

Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



GeneralRe: Design Question Pin
TheGermoz15-Nov-12 21:11
memberTheGermoz15-Nov-12 21:11 
AnswerRe: Design Question Pin
Rahul Rajat Singh15-Nov-12 22:43
memberRahul Rajat Singh15-Nov-12 22:43 
GeneralRe: Design Question Pin
TheGermoz16-Nov-12 0:14
memberTheGermoz16-Nov-12 0:14 
AnswerRe: Design Question Pin
Rahul Rajat Singh16-Nov-12 0:22
memberRahul Rajat Singh16-Nov-12 0:22 
AnswerRe: Design Question Pin
BobJanova16-Nov-12 0:12
memberBobJanova16-Nov-12 0:12 
GeneralRe: Design Question Pin
TheGermoz16-Nov-12 0:16
memberTheGermoz16-Nov-12 0:16 

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.


Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 25 Mar 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid