+ Reply to Thread
Results 1 to 2 of 2

Is a method or property better for manipulating several private variables and using inputs

  1. #1
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Is a method or property better for manipulating several private variables and using inputs

    I would like to make sure I'm using good practices for my first major project. When creating Get Properties, is it better to use methods to change multiple private variables and return objects in classes different that the class in which a property is defined?

    Here is a (working) specific excerpt from a Class I developed:

    Is (READ-ONLY) Public Property Get AllTradesBySpread(Bounds_ASD() As Integer, Optional SubCollection_ASD As Collection = Nothing) As Collection best-implemented as a method? It works, but I'm beginning to wonder if some of the properties I'm writing should be methods.

    Although the following code is long, only due to repetition, it's well-commented. It only manipulates two private variables (pNTradesInTradesBySpread & pAllTradesBySpread); however, many of my properties manipulate several.

    Please Login or Register  to view this content.
    Any feedback is appreciated.
    Last edited by joe31623; 12-08-2015 at 11:50 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,028

    Re: Is a method or property better for manipulating several private variables and using in

    This is a rather advanced question relating to object-oriented design. To answer this, it would be helpful to understand more about your class model.

    My gut feel is that this should be a method. Here is why. From a quick look at the code, I am guessing that the way you are using this property is to build it based on ad hoc demand. That means it is not truly part of the state of your object but rather the result of a service that your object performs when requested. A Get operation should just return a value; in this case there is a side-effect of creating the value on the fly. I am guessing that once this Get returns the property that the property is never referenced again by any method of this object until another Get, when it is again created using different criteria.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Follow-up question about variables [Private]
    By xlBunny in forum Excel - New Users/Basics
    Replies: 10
    Last Post: 04-23-2015, 11:47 PM
  2. Calculation Involving Multiple Inputs For Each Of Two Variables
    By ericrichard25 in forum Excel General
    Replies: 2
    Last Post: 01-26-2015, 09:18 PM
  3. Replies: 2
    Last Post: 03-11-2014, 03:36 PM
  4. Data table - two inputs that are variables
    By bp22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-15-2013, 03:13 PM
  5. [SOLVED] Workbook Property or Method
    By Gary''s Student in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2006, 11:15 AM
  6. Private modules and global variables
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-25-2005, 03:15 PM
  7. [SOLVED] Class Modules and Private Variables
    By Joe Cletcher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2005, 03:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1