|
-
Feb 16th, 2012, 05:50 PM
#1
Thread Starter
Hyperactive Member
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.
-
Feb 16th, 2012, 06:05 PM
#2
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
 
-
Feb 17th, 2012, 02:03 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|