Click here to Skip to main content
15,916,378 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error please help Pin
Richard MacCutchan7-Nov-11 4:03
mveRichard MacCutchan7-Nov-11 4:03 
QuestionShamos Pin
msafary6-Nov-11 21:54
msafary6-Nov-11 21:54 
AnswerRe: Shamos Pin
Richard MacCutchan6-Nov-11 22:46
mveRichard MacCutchan6-Nov-11 22:46 
Question"economics" of casting to an interface in a parameter declaration of a method ? Pin
BillWoodruff6-Nov-11 20:41
professionalBillWoodruff6-Nov-11 20:41 
AnswerRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
harold aptroot6-Nov-11 21:37
harold aptroot6-Nov-11 21:37 
AnswerRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
Luc Pattyn6-Nov-11 22:56
sitebuilderLuc Pattyn6-Nov-11 22:56 
AnswerRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
PIEBALDconsult7-Nov-11 1:49
mvePIEBALDconsult7-Nov-11 1:49 
AnswerRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
DaveyM697-Nov-11 11:11
professionalDaveyM697-Nov-11 11:11 
Hi Bill,

I know where you are coming from with this having being involved in some discussion on the same thread.

I agree with the others, there is no cost involved - to answer your question.

Another/different question is should you pass an object (disguised as an interface or not) to another for simplicity of communication between the objects?

Personally, I think not. An interface is a slight improvement to passing a concrete object, but I instinctively feel the 'secondary' object should be raising an event that the 'primary' object can choose to subscribe to or not depending on whatever logic is appropriate, and if subscribed - react or not. If the 'primary' needs to communicate with the 'secondary' then it should retain a reference to it - whether that is as an interface or not is irrelevant.

In other words, I see no particular improvement or benefit between these two, I disapprove of them both equally!

C#
public partial class FormPrimary : Form
{
    public FormPrimary()
    {
        InitializeComponent();
    }

    public void SetText(string text)
    {
        Text = text;
    }
}

public partial class FormSecondary : Form
{
    private FormPrimary primary;

    public FormSecondary()
        : this(null)
    { }
    public FormSecondary(FormPrimary primary)
    {
        InitializeComponent();
        this.primary = primary;
    }

    private void SetPrimaryText(string text)
    {
        if (primary != null)
        {
            primary.SetText(text);
        }
    }
}

C#
public interface IStuff
{
    void SetText(string text);
}

public partial class FormPrimary : Form, IStuff
{
    public FormPrimary()
    {
        InitializeComponent();
    }

    public void SetText(string text)
    {
        Text = text;
    }
}

public partial class FormSecondary : Form
{
    private IStuff primary;

    public FormSecondary()
        : this(null)
    { }
    public FormSecondary(IStuff primary)
    {
        InitializeComponent();
        this.primary = primary;
    }

    private void SetPrimaryText(string text)
    {
        if (primary != null)
        {
            primary.SetText(text);
        }
    }
}


Just my initial feelings and I am interested to see how this turns out!
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: "economics" of casting to an interface in a parameter declaration of a method ? Pin
BillWoodruff7-Nov-11 19:03
professionalBillWoodruff7-Nov-11 19:03 
GeneralRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
DaveyM697-Nov-11 21:36
professionalDaveyM697-Nov-11 21:36 
GeneralRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
Pete O'Hanlon7-Nov-11 23:19
mvePete O'Hanlon7-Nov-11 23:19 
GeneralRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
DaveyM698-Nov-11 6:45
professionalDaveyM698-Nov-11 6:45 
GeneralRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
BobJanova8-Nov-11 0:14
BobJanova8-Nov-11 0:14 
GeneralRe: "economics" of casting to an interface in a parameter declaration of a method ? Pin
DaveyM698-Nov-11 6:57
professionalDaveyM698-Nov-11 6:57 
AnswerNot so simple (Re: "economics" of casting to an interface in a parameter declaration of a method?) Pin
Sergey Alexandrovich Kryukov8-Nov-11 14:58
mvaSergey Alexandrovich Kryukov8-Nov-11 14:58 
QuestionOmar Gameel, Apriori Algorithm Please Help..!!! Pin
Member 78679836-Nov-11 11:29
Member 78679836-Nov-11 11:29 
GeneralRe: Omar Gameel, Apriori Algorithm Please Help..!!! Pin
harold aptroot6-Nov-11 11:41
harold aptroot6-Nov-11 11:41 
AnswerRe: Omar Gameel, Apriori Algorithm Please Help..!!! Pin
Dalek Dave6-Nov-11 12:54
professionalDalek Dave6-Nov-11 12:54 
Questionauto check DataGridViewCheckBoxColumn Pin
Danzy836-Nov-11 10:52
Danzy836-Nov-11 10:52 
AnswerRe: auto check DataGridViewCheckBoxColumn Pin
Dalek Dave6-Nov-11 12:57
professionalDalek Dave6-Nov-11 12:57 
AnswerRe: auto check DataGridViewCheckBoxColumn Pin
Dr.Walt Fair, PE6-Nov-11 16:59
professionalDr.Walt Fair, PE6-Nov-11 16:59 
AnswerRe: auto check DataGridViewCheckBoxColumn Pin
purnananda behera7-Nov-11 19:00
purnananda behera7-Nov-11 19:00 
QuestionHow to read an Autocad file with c# Pin
JUSTLOVE16-Nov-11 10:04
JUSTLOVE16-Nov-11 10:04 
AnswerRe: How to read an Autocad file with c# Pin
Richard MacCutchan6-Nov-11 10:19
mveRichard MacCutchan6-Nov-11 10:19 
GeneralRe: How to read an Autocad file with c# Pin
Dalek Dave6-Nov-11 12:57
professionalDalek Dave6-Nov-11 12:57 

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.