Results 1 to 4 of 4

Thread: method or function?

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    method or function?

    need some opinions: Let's say you have an object that you want to use over and over. you could either create an internal method to reset the class's fields back to defaults or you can create a function to do the same (property = nothing). what is considered the best practice?

    before I get flamed LOL, my boss wanted me to use the same objects over and over. is there a draw-back to this?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    You have three choices:
    1) A method - can take paremeters, but cannot return sucess/failure
    2) A function - also can take parameters, AND can return if it was successful or not
    3) A property - no parameters, no return value

    The choice is really yours and what you need to do. Do you need to pass in parameters? Then a method or function is needed. Do you care about a return value? Then use the function. If you don't need either, then a property will work.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    I tend to use a lot of boolean functions, just for the reason techgnome stated. Let's the calling function know if it succeeded. You could, I think, throw an exception to be caught in the calling function instead, we used to do that in C++ class.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    I would opt for a method. In general - a property is used to define the current state of an object, whereas a method manipulates in some way the data inside the object.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width