Guest dkode Posted June 26, 2003 Posted June 26, 2003 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? Quote
Guest dkode Posted June 26, 2003 Posted June 26, 2003 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 Quote
Administrators PlausiblyDamp Posted June 27, 2003 Administrators Posted June 27, 2003 Optional parameters are generally looked down on in .Net and they can have nasty side effects if used in public functions within a DLL. Function overloading is generally the recomended way. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Heiko Posted June 27, 2003 Posted June 27, 2003 (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 June 27, 2003 by Heiko Quote .nerd
Guest dkode Posted June 27, 2003 Posted June 27, 2003 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? Quote
Heiko Posted June 27, 2003 Posted June 27, 2003 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. Quote .nerd
wyrd Posted June 27, 2003 Posted June 27, 2003 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... } Quote Gamer extraordinaire. Programmer wannabe.
AndreRyan Posted June 28, 2003 Posted June 28, 2003 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 Quote .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?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.