Click here to Skip to main content
15,888,984 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: DialogBasics as in MFC. Pin
Richard MacCutchan16-May-13 21:07
mveRichard MacCutchan16-May-13 21:07 
GeneralRe: DialogBasics as in MFC. Pin
Bram van Kampen17-May-13 9:35
Bram van Kampen17-May-13 9:35 
GeneralRe: DialogBasics as in MFC. Pin
Richard MacCutchan17-May-13 22:45
mveRichard MacCutchan17-May-13 22:45 
QuestionI suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
M-Badger15-May-13 11:43
M-Badger15-May-13 11:43 
AnswerRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
Eddy Vluggen16-May-13 5:01
professionalEddy Vluggen16-May-13 5:01 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
M-Badger16-May-13 8:34
M-Badger16-May-13 8:34 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
Eddy Vluggen16-May-13 9:13
professionalEddy Vluggen16-May-13 9:13 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
M-Badger16-May-13 9:57
M-Badger16-May-13 9:57 
I think this is simply a variation on your suggestion (in effect), using a nested class.
VB
Public Class Class1

    Private _param As Double

    Public Sub New(ByVal amount As Double)
        Me._param = amount
    End Sub

    Public Property Param() As Double
        Get
            Return Me._param
        End Get
        Set(value As Double)
            If Not value = Me._param Then
                Me._param = value
            End If
        End Set
    End Property

    Public Function ToGrey() As ToGreyMethods
        Return New ToGreyMethods(Me)
    End Function

    Public Class ToGreyMethods

        Private _outer As Class1

        Public Sub New(ByRef outer As Class1)
            Me._outer = outer
        End Sub

        Public Sub Increase(ByVal amount As Double)
            Me._outer.Param += amount
        End Sub

        Public Sub Decrease(ByVal amount As Double)
            Me._outer.Param -= amount
        End Sub
    End Class

End Class

Module Module1

    Sub Main()
        Dim thing As Class1 = New Class1(10)
        thing.ToGrey.Increase(5)
        Console.WriteLine(thing.Param.ToString())
        thing.ToGrey.Decrease(10)
        Console.WriteLine(thing.Param.ToString())
        Console.ReadKey()
    End Sub

End Module

'Output is:
'15
'5

My only problem with this is that I can't seem to hide the nested class so one could be created at runtime manually rather than as a result of a call to ToGrey(), which starts to feel a bit messy or at least has the potential to get messy since I do.t know what would happen if, for example, you could do this.
VB
Public Sub Example()
    Dim thing as Class1 = New Class1(10)
    Dim whoops as ToGreyMethods = thing.ToGrey()
    'I now have an instance of an object that I can start using to change the thing object without directly referring to thing, feels like a recipe for confusion...
End Sub

GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
Eddy Vluggen16-May-13 11:25
professionalEddy Vluggen16-May-13 11:25 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
M-Badger16-May-13 9:58
M-Badger16-May-13 9:58 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
Eddy Vluggen16-May-13 11:26
professionalEddy Vluggen16-May-13 11:26 
AnswerRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
jschell16-May-13 7:57
jschell16-May-13 7:57 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
M-Badger16-May-13 8:37
M-Badger16-May-13 8:37 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
jschell17-May-13 10:13
jschell17-May-13 10:13 
AnswerRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
TnTinMn16-May-13 13:37
TnTinMn16-May-13 13:37 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
M-Badger17-May-13 6:49
M-Badger17-May-13 6:49 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
TnTinMn17-May-13 8:33
TnTinMn17-May-13 8:33 
GeneralRe: I suspect there's a Pattern for This: Optional Parameters vs. Overloading Pin
M-Badger17-May-13 21:47
M-Badger17-May-13 21:47 
QuestionAssembly Loading Pin
#realJSOP14-May-13 5:10
mve#realJSOP14-May-13 5:10 
AnswerRe: Assembly Loading Pin
Jasmine250114-May-13 6:18
Jasmine250114-May-13 6:18 
GeneralRe: Assembly Loading Pin
#realJSOP14-May-13 6:57
mve#realJSOP14-May-13 6:57 
GeneralRe: Assembly Loading Pin
Jasmine250114-May-13 7:12
Jasmine250114-May-13 7:12 
AnswerRe: Assembly Loading Pin
jschell14-May-13 9:22
jschell14-May-13 9:22 
GeneralRe: Assembly Loading Pin
Jasmine250114-May-13 11:36
Jasmine250114-May-13 11:36 
GeneralRe: Assembly Loading Pin
jschell15-May-13 8:23
jschell15-May-13 8:23 

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.