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

.NET (Core and Framework)

 
AnswerRe: validating on custom datagridview column Pin
sh-a22-May-13 4:27
sh-a22-May-13 4:27 
QuestionDialogBasics asin MFC. Pin
Bram van Kampen15-May-13 13:58
Bram van Kampen15-May-13 13:58 
AnswerRe: DialogBasics asin MFC. Pin
Richard MacCutchan15-May-13 22:10
mveRichard MacCutchan15-May-13 22:10 
GeneralRe: DialogBasics as in MFC. Pin
Bram van Kampen16-May-13 14:05
Bram van Kampen16-May-13 14:05 
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 
I did have a bunch of similar public methods for converting an RGB structure to grey scale but decided it made the class too complicated so I changed them to private and created an Enum which was used as a parameter for a public method which then called those private methods method using switch.

One of the private methods then developed a need for a parameter, but only one of them. I made the parameter optional but then stumbled into the problem of public shared methods not being considered as constants, so I switched to overloading for this method and wanted to add an optional Enum to represent the two variants of that one method, this smelt bad. So I thought to use overloading again, but the second version of the method would still be able to accept all the options of the first Enum, even though only one was relevant, the one that needed the second Enum, still smelt bad.

I'm struggling to follow this explanation myself, so if code helps then here it is (simplified). I don't like it.
I could possibly use the second ToGreyScale method with just the LumaEnum parameter but that, to my mind, makes the use of the class problematic since it's not intuitive. Calling the second method GreyScalebyLuminosity makes a nonsense of trying to get rid of all those differently named GreyScale methods.

Is there a pattern I can use here? Or just a better design than this?

VB
Public Overloads Sub ToGreyScale(ByVal method As RGBGreyScaleMethod)
    Select Case method
        Case RGBGreyScaleMethod.Average
            Me.GreyScaleByAverage()
        Case RGBGreyScaleMethod.BlueChannel
            Me.GreyScaleFromBlue()
        Case RGBGreyScaleMethod.Decompose
            Me.Decompose()
        Case RGBGreyScaleMethod.Luminosity
            Me.GreyScaleByLuminosity()
        Case Else
            Throw New ArgumentOutOfRangeException()
    End Select
End Sub

Public Overloads Sub ToGreyScale(ByVal method As RGBGreyScaleMethod, ByVal factors as LumaEnum)
    Select Case method
        Case RGBGreyScaleMethod.Luminosity
            Select Case factors
                Case LumaEnum.BT709
                    Me.GreyScaleByLuminosity(LumaFactors.BT709)
                Case LumaEnum.BT601
                    Me.GreyScaleByLuminosity(LumaFactors.BT601)
                Case LumaEnum.GIMP
                    Me.GreyScaleByLuminosity(LumaFactors.GIMP)
                Case Else
                    Throw New ArgumentOutOfRangeException()
            End Select
        Case Else
            Throw New ArgumentOutOfRangeException()
    End Select
End Sub

Private Overloads Sub GreyScaleByLuminosity()
    Me.GreyScaleByLuminosity(LumaFactors.BT709) 'Shared method in LumaFactors Structure
End Sub

Private Overloads Sub GreyScaleByLuminosity(ByVal factors As LumaFactors)
    Dim c As Double = Me.Luminosity(factors)
    Me._Red = CInt(c)
    Me._Green = CInt(c)
    Me._Blue = CInt(c)
End Sub

Public Enum LumaEnum
    BT709
    BT601
    GIMP
End Enum

Public Enum
    Average
    BlueChannel
    Decompose
    Luminosity
    Desaturate
    Lightness
    RedChannel
    GreenChannel
End Enum

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 
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 

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.