473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to implement a "helper" class

Let's say I have a class called ClassA which has a bunch of member
variables, properties, private and public methods. Then, let's say
that I want to create another class, ClassACalcEngine, that will do
certain calc's related to ClassA, but together with some fields that
would be populated just for the calc's...not related to ClassA itself
(e.g. PeriodBeginDate, PeriodEndDate, etc.). However, to perform the
calculations, ClassACalcEngine needs access to certain property
values, and public methods, of ClassA. What is the best way to
implement something like this?

I had originally thought that I'd have a member variable in ClassA
which was an instance of a ClassACalcEngine. However, I don't know how
the ClassACalcEngine will have access to the needed properties and
methods of ClassA. It should be noted that ClassACalcEngine would only
ever calculate things for a ClassA (i.e. has no value unless
associated with a ClassA).
Jan 12 '08 #1
4 1461
On Jan 12, 10:28*am, BobRoyAce <b...@omegasoftwareinc.comwrote:
Let's say I have a class called ClassA which has a bunch of member
variables, properties, private and public methods. Then, let's say
that I want to create another class, ClassACalcEngine, that will do
certain calc's related to ClassA, but together with some fields that
would be populated just for the calc's...not related to ClassA itself
(e.g. PeriodBeginDate, PeriodEndDate, etc.). However, to perform the
calculations, ClassACalcEngine needs access to certain property
values, and public methods, of ClassA. What is the best way to
implement something like this?

I had originally thought that I'd have a member variable in ClassA
which was an instance of a ClassACalcEngine. However, I don't know how
the ClassACalcEngine will have access to the needed properties and
methods of ClassA. It should be noted that ClassACalcEngine would only
ever calculate things for a ClassA (i.e. has no value unless
associated with a ClassA).
You might consider implementing ClassACalcEngine as a nested class -
in other words something like:

class ClassA
calc as classacalcengine
sub new()
calc = new classacalcengine (me)
end sub

class ClassACalcEngine
parent as classA

sub new (byval parent as classa)
' classaclacengine instance now has access to all members
(including
' private members) of parent classa instance
me.parent=parent
end sub
end class
end class

Nested classes can even access private members of their enclosing
class.

HTH

--
Tom Shelton
Jan 12 '08 #2
BobRoyAce <br**@omegasoftwareinc.comwrote in news:f7952ea0-32e2-4aa1-
9e***************@l1g2000hsa.googlegroups.com:
Thanks for the reply, Tom. I had thought of doing something similar
except that I would have defined the ClassACalcEngine in a separate
file, outside of the ClassA class.
Why areyou thinking in terms of "files"? You should be thinking in terms of
objects :-)
Soooo, basically, the solution includes ClassA having a reference to a
ClassACalcEngine, and vice-versa. For some reason, I think I had it in
my head that that was "not good" or violated some better way to do it
(i.e. design pattern).
You could always inherit from a base class - ClassAClacEngine can always
extend the base object with additional properties.

--
sp**********@rogers.com (Do not e-mail)
Jan 12 '08 #3
I've got it in my head that it's not "ideal" to have very large
classes with tons of properties and methods. I'm not sure where I got
that from. Perhaps from my days in database design where I was taught
that it's not ideal to have tables with lots and lots of fields.

Besides that, I was thinking that having a separate class to do all
the calc'ing was a better way to encapsulate all the calc logic. I
suppose that, by doing the nested class, I do just that.
Jan 13 '08 #4
BobRoyAce wrote:
Let's say I have a class called ClassA which has a bunch of member
variables, properties, private and public methods. Then, let's say
that I want to create another class, ClassACalcEngine, that will do
certain calc's related to ClassA, but together with some fields that
would be populated just for the calc's...not related to ClassA itself
(e.g. PeriodBeginDate, PeriodEndDate, etc.). However, to perform the
calculations, ClassACalcEngine needs access to certain property
values, and public methods, of ClassA. What is the best way to
implement something like this?

I had originally thought that I'd have a member variable in ClassA
which was an instance of a ClassACalcEngine. However, I don't know how
the ClassACalcEngine will have access to the needed properties and
methods of ClassA. It should be noted that ClassACalcEngine would only
ever calculate things for a ClassA (i.e. has no value unless
associated with a ClassA).
Since the helper class is essentially useless w/o ClassA, what about
overriding the constructor to include a reference to ClassA, then store
the reference as a member variable. Then the helper would have full
access to the dataclass.

-ca
Jan 13 '08 #5

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

Similar topics

4
by: Robert Ferrell | last post by:
I have a style question. I have a class with a method, m1, which needs a helper function, hf. I can put hf inside m1, or I can make it another method of the class. The only place hf should ever...
2
by: Tobias Erbsland | last post by:
Hello I have a problem with an error message. I created a new class (as OpenSSL helper): class DataBlock { public: DataBlock(); DataBlock( unsigned int size );
10
by: Andreas Müller | last post by:
Hi all, I have a class SwitchCursor, that implements IDisposable. Is it legal to use an object that is not assigned to a reference inside a using statement like this: using(new...
4
by: Rahul Anand | last post by:
Getting SQL Exception when trying to implement Connection based Trasaction using SQL Helper class. I am using the follwing function to execute my stored procs: -=-=-=- ExecuteScalar(ByVal...
10
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what...
6
by: Vincent Finn | last post by:
Hi, I am trying to store an object in the Session() I have a VB.Net control which is loaded in an asp page and then calls a function in my webservice (also written in VB.Net) The web...
13
by: learning | last post by:
Hi I have a static class written by other team which encapsulates a database instance. but I need to extend it to incldue other things. I know that C# static class is sealed and can;t be inherited...
8
by: Floortje | last post by:
Hi i have been struggeling with this question for quite some time now. I have some helper classes that handle images (upload an image, create thumbnails and show a imagelist), links (add link,...
21
by: raylopez99 | last post by:
In the otherwise excellent book C# 3.0 in a Nutshell by Albahari et al. (3rd edition) (highly recommended--it's packed with information, and is a desktop reference book) the following statement is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.