Click here to Skip to main content
15,890,438 members
Home / Discussions / C#
   

C#

 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Norris Chappell22-May-15 12:52
Norris Chappell22-May-15 12:52 
AnswerRe: Trying to make a DataGridView field a color if a condition is met. Pin
Mathi Mani22-May-15 13:00
Mathi Mani22-May-15 13:00 
GeneralRe: Trying to make a DataGridView field a color if a condition is met. Pin
Norris Chappell23-May-15 11:11
Norris Chappell23-May-15 11:11 
Questionway around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 6:49
professionalBillWoodruff22-May-15 6:49 
AnswerRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Sascha Lefèvre22-May-15 7:04
professionalSascha Lefèvre22-May-15 7:04 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 21:12
professionalBillWoodruff22-May-15 21:12 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Sascha Lefèvre24-May-15 3:33
professionalSascha Lefèvre24-May-15 3:33 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff24-May-15 22:42
professionalBillWoodruff24-May-15 22:42 
Thanks, Sascha, for another evocative response !

Bill: "have the Interface declare method signatures for such actions as Dictionary ... 'Add, 'Remove, etc. ? ... in the Interface ... declare the signature of a method whose "only purpose" is to set the initial Value of the Property ?"
Sascha Lefèvre wrote:
Generally I think any complex member of a class shouldn't be publicly exposed in order to be able to control which actions can be performed on it.
I've been thinking about this ... seriously ... while taking Richard Deeming's advice and studying explicit Interface implementation.

Right now, my reason for declaring the Dictionary in the Interface is based on (what I think is) the "contractual" role of Interfaces: requiring that any Class that "claims" it can do/provide certain facilities guarantees it implements the requisite objects, methods, properties in order to compile.

If I use explicit Interface implementation, I can declare an object, like a Dictionary, in the Interface and still keep it 'private so the end-user of the Class can only access it by methods I define and publish, like 'Add, 'Remove. Like this:
C#
public interface IRequire
{
    Dictionary<string, int> RequiredDictionary { get; }
}

public class Example : IRequire
{
    // explicit implementation of IRequire
    Dictionary<string, int> IRequire.RequiredDictionary
    {
        get { return this.internalDictionary; }
    }

    private Dictionary<string, int> internalDictionary { set; get; }

    public Example()
    {
        internalDictionary = new Dictionary<string, int>();
    }

    public void AddToRequiredDictionary(string str, int i)
    {
        internalDictionary.Add(str, i);
    }

    public void RemoveRequiredDictionary(string key)
    {
        internalDictionary.Remove(key);
    }
}
So, if you have time to respond, I'd appreciate you analysis of this technique as compared to defining the Interface and Class focusing on exposing the methods:
C#
public interface IRequire
{
    void AddEntry(string key, int value );
    void RemoveEntry(string key);
}

public class Example : IRequire
{
    private Dictionary<string, int> internalDictionary { set; get; }

    public Example()
    {
        internalDictionary = new Dictionary<string, int>();
    }

    public void AddEntry(string key, int value)
    {
        internalDictionary.Add(key, value);
    }

    public void RemoveEntry(string key)
    {
        internalDictionary.Remove(key);
    }
}
Of course, one could expose both object (Dictionary) and methods by simply combining the two implemenations shown here: would that be "over-kill" ?

I, for one, look forward to the upcoming provision in future versions of C# of method constraints: that's been mentioned in something I read recently (mabye Eric Lippert's blog ?), but I locate find the source right now.

cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.

GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Sascha Lefèvre25-May-15 4:21
professionalSascha Lefèvre25-May-15 4:21 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff25-May-15 7:54
professionalBillWoodruff25-May-15 7:54 
AnswerRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Richard Deeming22-May-15 7:11
mveRichard Deeming22-May-15 7:11 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 21:27
professionalBillWoodruff22-May-15 21:27 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff24-May-15 22:46
professionalBillWoodruff24-May-15 22:46 
AnswerRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Pete O'Hanlon22-May-15 8:06
mvePete O'Hanlon22-May-15 8:06 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 21:33
professionalBillWoodruff22-May-15 21:33 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Pete O'Hanlon22-May-15 21:47
mvePete O'Hanlon22-May-15 21:47 
AnswerRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
Alan N22-May-15 14:15
Alan N22-May-15 14:15 
GeneralRe: way around limitations of WinForms treatment of Public Proprties implementing an Interface ? Pin
BillWoodruff22-May-15 21:35
professionalBillWoodruff22-May-15 21:35 
QuestionHow to get the directory where DDL is installed Pin
Antonio Guedes22-May-15 6:14
Antonio Guedes22-May-15 6:14 
AnswerRe: How to get the directory where DDL is installed Pin
Eddy Vluggen22-May-15 6:56
professionalEddy Vluggen22-May-15 6:56 
GeneralRe: How to get the directory where DDL is installed Pin
Antonio Guedes22-May-15 10:06
Antonio Guedes22-May-15 10:06 
GeneralRe: How to get the directory where DDL is installed Pin
Richard Andrew x6422-May-15 12:28
professionalRichard Andrew x6422-May-15 12:28 
QuestionHow to implement Save As functionality in C# Pin
RajuPrasad8222-May-15 3:49
professionalRajuPrasad8222-May-15 3:49 
AnswerRe: How to implement Save As functionality in C# Pin
Dave Kreskowiak22-May-15 4:09
mveDave Kreskowiak22-May-15 4:09 
GeneralRe: How to implement Save As functionality in C# Pin
RajuPrasad8222-May-15 4:24
professionalRajuPrasad8222-May-15 4:24 

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.