473,471 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Best Practice ?

Hello;

Given a class A. class A has a function:

calculate()

Class A can calls another Class: B

The problem is: Class B also wants to use the calculate() function. I do
not think it is a good way to duplicate the calculate() function in both
classes.

How do I solve such a problem ?

Thanks in advance!
M.

Nov 20 '05 #1
8 922
* "Marten Van Keer" <ma****@c3.be> scripsit:
Given a class A. class A has a function:

calculate()

Class A can calls another Class: B

The problem is: Class B also wants to use the calculate() function. I do
not think it is a good way to duplicate the calculate() function in both
classes.

How do I solve such a problem ?


Maybe creating a base class which provides the 'Calculate' function and
inheriting ('Inherits') from this class will help.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
If calculate doesn't really require classA to be instantiated, you can use a
shared function

publc classA
public shared function calculate() as integer
....
end function
end class

<from classB>
classA.calculate()

"Marten Van Keer" <ma****@c3.be> wrote in message
news:40*********************@news.skynet.be...
Hello;

Given a class A. class A has a function:

calculate()

Class A can calls another Class: B

The problem is: Class B also wants to use the calculate() function. I do
not think it is a good way to duplicate the calculate() function in both
classes.

How do I solve such a problem ?

Thanks in advance!
M.

Nov 20 '05 #3
Cor
Hi Marten,

If it is such an important function than in my opinion of course a class by
itself.

Cor


Nov 20 '05 #4
Marten,
In addition to the other's comments.

Can you provide more details on what you are attempting to accomplish?
I do
not think it is a good way to duplicate the calculate() function in both
classes. You are correct is not good to copy the code for Calculate into both A & B.
However both can have a method called Calculate that performs a different
calculation based on being either an A or a B object.

In addition to the others comments about Shared & Inherits: If a B object
needs to call the Calculate method of an A object, then B needs either a
class variable of type A, or B's method needs an A object as a parameter.

Again can you provide more details, as I am not following what you want.
Maybe include 10 to 15 lines of code to show what you have now, that you are
trying to avoid.

Hope this helps
Jay

"Marten Van Keer" <ma****@c3.be> wrote in message
news:40*********************@news.skynet.be... Hello;

Given a class A. class A has a function:

calculate()

Class A can calls another Class: B

The problem is: Class B also wants to use the calculate() function. I do
not think it is a good way to duplicate the calculate() function in both
classes.

How do I solve such a problem ?

Thanks in advance!
M.

Nov 20 '05 #5
Cor
Hi Jay B,

I seldom start a discussion with you and this one is very slippery ground
because I was you did a lot of investigations in the present time.

But with this one I had to think about Toms message to me about
encapsulation.

And this looks me someting for it.

My idea is, that when you have calculations, let say incometax for a
country, it has to be in one class and not a part of an other class.

And especialy not as part form a class (not a supplier) which has a function
in it that can be used in other programs.

My 2 cents, I am prepared to loose this discussion this time.

:-))

Cor

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schreef in bericht
news:ux**************@tk2msftngp13.phx.gbl...
Marten,
In addition to the other's comments.

Can you provide more details on what you are attempting to accomplish?
I do
not think it is a good way to duplicate the calculate() function in both
classes. You are correct is not good to copy the code for Calculate into both A &

B. However both can have a method called Calculate that performs a different
calculation based on being either an A or a B object.

In addition to the others comments about Shared & Inherits: If a B object
needs to call the Calculate method of an A object, then B needs either a
class variable of type A, or B's method needs an A object as a parameter.

Again can you provide more details, as I am not following what you want.
Maybe include 10 to 15 lines of code to show what you have now, that you are trying to avoid.

Hope this helps
Jay

"Marten Van Keer" <ma****@c3.be> wrote in message
news:40*********************@news.skynet.be...
Hello;

Given a class A. class A has a function:

calculate()

Class A can calls another Class: B

The problem is: Class B also wants to use the calculate() function. I do not think it is a good way to duplicate the calculate() function in both
classes.

How do I solve such a problem ?

Thanks in advance!
M.


Nov 20 '05 #6
Cor,
I'm sorry: Something is being lost in the translation today:
But with this one I had to think about Toms message to me about
encapsulation. Encapsulation is good! I vaguely remember your thread with Tom.
My idea is, that when you have calculations, let say incometax for a
country, it has to be in one class and not a part of an other class. Correct the calculation for incometax by country should be in a specific
class. Especially when you want the calculation to be polymorphic.
Polymorphism is good!
And especialy not as part form a class (not a supplier) which has a function in it that can be used in other programs. ?? I'm not following this statement, can you elaborate?

Thanks
Jay
"Cor" <no*@non.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl... Hi Jay B,

I seldom start a discussion with you and this one is very slippery ground
because I was you did a lot of investigations in the present time.

But with this one I had to think about Toms message to me about
encapsulation.

And this looks me someting for it.

My idea is, that when you have calculations, let say incometax for a
country, it has to be in one class and not a part of an other class.

And especialy not as part form a class (not a supplier) which has a function in it that can be used in other programs.

My 2 cents, I am prepared to loose this discussion this time.

:-))

Cor

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schreef in bericht news:ux**************@tk2msftngp13.phx.gbl...
Marten,
In addition to the other's comments.

Can you provide more details on what you are attempting to accomplish?
I do
not think it is a good way to duplicate the calculate() function in both classes.

You are correct is not good to copy the code for Calculate into both A &

B.
However both can have a method called Calculate that performs a different
calculation based on being either an A or a B object.

In addition to the others comments about Shared & Inherits: If a B object needs to call the Calculate method of an A object, then B needs either a
class variable of type A, or B's method needs an A object as a parameter.
Again can you provide more details, as I am not following what you want.
Maybe include 10 to 15 lines of code to show what you have now, that you

are
trying to avoid.

Hope this helps
Jay

"Marten Van Keer" <ma****@c3.be> wrote in message
news:40*********************@news.skynet.be...
Hello;

Given a class A. class A has a function:

calculate()

Class A can calls another Class: B

The problem is: Class B also wants to use the calculate() function. I

do not think it is a good way to duplicate the calculate() function in both classes.

How do I solve such a problem ?

Thanks in advance!
M.



Nov 20 '05 #7
Cor
Hi Jay,
-----------------------------
I'm sorry: Something is being lost in the translation today:

Was not the translation just an ordinary forgotten correction error from
which I was hoping that your brain autocorrect would change it when I saw
it. It had to be:

I seldom start a discussion with you and this one is on very slippery ground
because I know you did many investigations in the present time.
---------------------------
This was the question from the OP:

The problem is: Class B also wants to use the calculate() function. I do
not think it is a good way to duplicate the calculate() function in both
classes.
--------------------
And I think that is not good to do it this way. He did want to use the
function from class A in class B without extra code. I said it is better to
build a separate "calculate" class. (And use that as well in A as in B of
course)

Cor
Nov 20 '05 #8
Cor,
And I think that is not good to do it this way. He did want to use the
function from class A in class B without extra code. I said it is better to build a separate "calculate" class. (And use that as well in A as in B of
course) Yes I agree, when its a common "calculation" that is "shared" by both
classes, yet is not specific to either class, a separate calculation class
is the way to go.

It really depends on what the OP is actually doing...

Thanks
Jay

"Cor" <no*@non.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... Hi Jay,
-----------------------------
I'm sorry: Something is being lost in the translation today: Was not the translation just an ordinary forgotten correction error from
which I was hoping that your brain autocorrect would change it when I saw
it. It had to be:

I seldom start a discussion with you and this one is on very slippery

ground because I know you did many investigations in the present time.
---------------------------
This was the question from the OP:

The problem is: Class B also wants to use the calculate() function. I do
not think it is a good way to duplicate the calculate() function in both
classes.
--------------------
And I think that is not good to do it this way. He did want to use the
function from class A in class B without extra code. I said it is better to build a separate "calculate" class. (And use that as well in A as in B of
course)

Cor

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
3
by: fuchsia555 | last post by:
hi you can tell your opinion which is the best web hosting
1
by: Man4ish | last post by:
Hi, I am planning to learn JSP. Which is the best book for it? Thanks in advance.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.