Jump to content
Xtreme .Net Talk

Optional Parameters?


Recommended Posts

Guest dkode
Posted

I am creating a UML layout of one of my DALC, and i have a quick question

 

This DALC can accept many different parameters:

 

No parameters : all db rows

sbuid : specific sbuid

revid : specific revid

revtypeid : specific revtypeid

month : specific month

year : specific year

goalamount : greater than / less than

 

I originally started making a seperate method for each parameter but then i noticed that all of these paramters can be used in conjunction. IE: they want the revenue goals that are a specific SbuID and specific RevType for a specific year.

 

If you know what i mean, there can be alot of different combonations

 

Is there a way to fit all of this into one method? if so how can i do so?

Guest dkode
Posted

Ok,

 

I think I might have figured out a way,

 

someone please let me know if I am going about this wrong. Thank you

 

	Public Shared Function GetRevenueGoals (Optional ByVal RevenueID As Integer = 0, _
							Optional ByVal SbuID As Integer = 0, _
							Optional ByVal RevenueTypeID As Integer = 0, _
							Optional ByVal Month As Integer = 0, _
							Optional ByVal Year As Integer = 0) As RevenueGoalCollection
		
	End Function

Posted (edited)

Overloading would require you to overload all possible permutations.

 

How about declaring a class DALCParameters with a public property for each of your cases as described above.

 

You can then pass this class as the single parameter.

If, in the future, you'd also want to search for a specific day, you just change the DALCParameters class. All interfaces remain the same.

 

For your convenience, you can also add several constructors.

Edited by Heiko
.nerd
Guest dkode
Posted

Could i create the parameters class as a structure?

 

i'm still trying to figure out the uses of a structure and an interface. I understand the basic concept of both, but I do not know when to use them/how they are useful?

Posted

Never used structures so far.

 

When I mentioned "Interfaces" I wasn't talking of "use defined interfaces" (IMySpecialInterface), perhaps I should have written

"signature" instead.

 

So :)

 

...

 

You can then pass this class as the single parameter.

If, in the future, you'd also want to search for a specific day, you just change the DALCParameters class. All *signature* remain the same.

.nerd
Posted

Creating a struct RevenueGoals and then passing it into GetRevenueGoals would probably be much better for what you're doing.

 

public struct RevenueGoals {
  public int RevenueID = 0;
  public int SbuID = 0;
  // ...
}

public void GetRevenueGoals(RevenueGoals revenues) {
  if (revenues.RevenueID != 0) {
     // whatever..
  }
  // etc...
}

Gamer extraordinaire. Programmer wannabe.
Posted

Public Structure RevenueGoals
  Public RevenueID as Integer = 0
  Public SbuID as Integer = 0
  ' ...
End Structure

Public Sub GetRevenueGoals(ByVal revenues as RevenueGoals)
  'Do Stuff
End Sub

You can change the structure to a class

Public Class MyParameters
    Protected _RevenueID as Integer
    Proteted _SbuID as Integer

    Public Property RevenueID() as Integer
        Get
             Return _RevenueID
        End Get
        Set(ByVal Value as Integer)
             _RevenueID = Value
        End Set
    End Property

    Public Property SbuID() as Integer
        Get
            Return _SbuID
        End Get
        Set(ByVal Value as Integer)
            _SbuID = Value
        End Set
    End Property
End Class

Public Class DoStuff
   Public Sub GetRevenueGoals(ByVal revenues as MyParameters)
      If revenues Is Nothing Then Exit Sub

      'Do Stuff
   End Sub
End Class

Or the overloaded functions means multiple declarations

Public Shared Function GetRevenueGoals (ByVal RevenueID As Integer) As RevenueGoalCollection
Public Shared Function GetRevenueGoals (ByVal RevenueID As Integer, ByVal SbuID As Integer) As RevenueGoalCollection
Public Shared Function GetRevenueGoals (ByVal RevenueID As Integer, ByVal Year As Short) As RevenueGoalCollection
'etc

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...