Results 1 to 3 of 3

Thread: Grouping Procedures & Functions

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    407

    Grouping Procedures & Functions

    Hi Guys,
    I think I'm just missing how to implement this. Say I have two different classes. Class A, and Class B which reside in separate files. Objects in class A and class B can do certain things commonly like format a number to two decimals which is in a commons class. So how do you implement that?

    So going back to my examples of class A and class B with a two decimal number formatter in a commons class.

    What I want to do is make a call like this:
    In class A
    mynumber = twoDecimal(anumber);

    Do you have to do an inhertance thing? When I do that it doesn't look quite the way I want it. It looks something like
    mynumber = commons.twoDecimal(anumber)

    I don't like the way that looks. Basically I'd just like a class or a file where I can stash common procedures and functions that can be used throughout my project.
    Thanks.
    My Websites
    SharpMP3 - MP3 Design Articles www.sharpmp3.com
    Yobbers - Job Search www.yobbers.com
    Lets Trend - Methods For Riding Stock Trends www.letstrend.com

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Grouping Procedures & Functions

    There are two different questions there. The answer to the final question is different from the answer to the rest of the post. The answer to the final question is that you can either put all of the common methods in a module, or you can build a class library with them and reference the library in any project that needs them.

    The answer to the rest of the post is probably to create a class that has the functionality, and include an instance of that class in both A and B. Inheritance is not going to work quite as well, though it could also be made to work.
    My usual boring signature: Nothing

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Grouping Procedures & Functions

    Do both class A and B have this formatting function ? If so you can define an abstract base class and declare that twoDecimal method as MustOverride then have both these classes inherit and implement it.

    Or...If the method works in both classes the exact same way, you can define the base class(not abstract this time) and implement the method there and just have both Class A and B inherit from it.

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