473,322 Members | 1,494 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,322 software developers and data experts.

OOP/Design question

Hi!

I have a class Bank and a Class BankAccount. A Bank can contains multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable
in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #1
8 1257

"codymanix" <do*********************@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi!

I have a class Bank and a Class BankAccount. A Bank can contains multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable
in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?

Personally, instead of having Bank hold all data for accounts, I'd break the
data down and store it in each BankAccount class. However, to answer your
question as posed I'd just pass the data reference into the account at
construction. Is it one row per account? If so then just pass the
appropriate row into the constructor. If its multiple rows pass in a
DataView.
--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #2
"codymanix" <do*********************@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi!

I have a class Bank and a Class BankAccount. A Bank can contains multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable
in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?


Yeah.

They are just called "internal" isntead of friend. Ok, not exactly the same,
but VERY close.
--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
(CTO PowerNodes Ltd.)
---

Still waiting for ObjectSpaces? Try the EntityBroker today - more versatile,
more powerfull.
And something in use NOW. for the projects you have to deliver - NOW.
Nov 15 '05 #3
> > I have a class Bank and a Class BankAccount. A Bank can contains
multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?
Yeah.

They are just called "internal" isntead of friend. Ok, not exactly the

same, but VERY close.

When my application is only one Assembly (which in it is in most cases),
then declaring something internal is the same as making it public.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #4
> > I have a class Bank and a Class BankAccount. A Bank can contains
multiple
BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?

Personally, instead of having Bank hold all data for accounts, I'd break

the data down and store it in each BankAccount class. However, to answer your
question as posed I'd just pass the data reference into the account at
construction. Is it one row per account? If so then just pass the
appropriate row into the constructor. If its multiple rows pass in a
DataView.

This seems the best Idea to me. But the constructor of the BankAccount is
still public.
Ideally it would only be visible to the Bank itself. Do you think putting
the BankAccount
class into the Bank as a local class would solve that problem?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #5

"Thomas Tomiczek [MVP]" <t.********@thona-consulting.com> wrote in message
news:OO**************@tk2msftngp13.phx.gbl...
"codymanix" <do*********************@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi!

I have a class Bank and a Class BankAccount. A Bank can contains multiple BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable in Bank, but I don't want to expose the datatable as a public property.

Since C# does not support friend classes, what is the best solutuion for
this problem?
Yeah.

They are just called "internal" isntead of friend. Ok, not exactly the

same, but VERY close.

Internal restricts access to the classes in an assembly. An assembly usually
contains many classes. Friend, at least as defined in C++, restricts access
to a single class, a single member of that class, or a single non
member.

/Magnus Lidbom


Nov 15 '05 #6

"codymanix" <do*********************@gmx.de> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
I have a class Bank and a Class BankAccount. A Bank can contains multiple BankAccounts (logical, isn't it?). The central Bank object contains a
datatable which holds the data of all bankaccounts.

This means, the class BankAccount must have access rights to the datatable in Bank, but I don't want to expose the datatable as a public property.
Since C# does not support friend classes, what is the best solutuion for this problem?

Personally, instead of having Bank hold all data for accounts, I'd break

the
data down and store it in each BankAccount class. However, to answer your question as posed I'd just pass the data reference into the account at
construction. Is it one row per account? If so then just pass the
appropriate row into the constructor. If its multiple rows pass in a
DataView.

This seems the best Idea to me. But the constructor of the BankAccount is
still public.
Ideally it would only be visible to the Bank itself. Do you think putting
the BankAccount
class into the Bank as a local class would solve that problem?

A contained class would work. Its a bit harder to work with(The type name is
Namespace.Bank.BankAccount now) but it should be sufficent. Just use a
private constructor(that is, unless my head is fooling with me today). --
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #7
> > > > I have a class Bank and a Class BankAccount. A Bank can contains
multiple
> BankAccounts (logical, isn't it?). The central Bank object contains a > datatable which holds the data of all bankaccounts.
>
> This means, the class BankAccount must have access rights to the datatable
> in Bank, but I don't want to expose the datatable as a public property. >
> Since C# does not support friend classes, what is the best solutuion for > this problem?
>

Personally, instead of having Bank hold all data for accounts, I'd
break
the
data down and store it in each BankAccount class. However, to answer your question as posed I'd just pass the data reference into the account at
construction. Is it one row per account? If so then just pass the
appropriate row into the constructor. If its multiple rows pass in a
DataView.

This seems the best Idea to me. But the constructor of the BankAccount

is still public.
Ideally it would only be visible to the Bank itself. Do you think putting the BankAccount
class into the Bank as a local class would solve that problem?

A contained class would work. Its a bit harder to work with(The type name

is Namespace.Bank.BankAccount now) but it should be sufficent. Just use a
private constructor(that is, unless my head is fooling with me today).

If the ctor would be private, nobody but the BankAccount itself can
instantiate a BankAccount.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #8

"cody" <do*********************@gmx.de> wrote in message
news:bv************@ID-176797.news.uni-berlin.de...
> > I have a class Bank and a Class BankAccount. A Bank can contains
multiple
> > BankAccounts (logical, isn't it?). The central Bank object contains
a
> > datatable which holds the data of all bankaccounts.
> >
> > This means, the class BankAccount must have access rights to the
datatable
> > in Bank, but I don't want to expose the datatable as a public property.
> >
> > Since C# does not support friend classes, what is the best
solutuion
for
> > this problem?
> >
>
> Personally, instead of having Bank hold all data for accounts, I'd

break the
> data down and store it in each BankAccount class. However, to answer

your
> question as posed I'd just pass the data reference into the account
at > construction. Is it one row per account? If so then just pass the
> appropriate row into the constructor. If its multiple rows pass in a
> DataView.
This seems the best Idea to me. But the constructor of the BankAccount

is still public.
Ideally it would only be visible to the Bank itself. Do you think putting the BankAccount
class into the Bank as a local class would solve that problem?

A contained class would work. Its a bit harder to work with(The type

name is
Namespace.Bank.BankAccount now) but it should be sufficent. Just use a
private constructor(that is, unless my head is fooling with me today).

If the ctor would be private, nobody but the BankAccount itself can
instantiate a BankAccount.


Ya, I had scoping rules turned upside down, thats what happens when you try
to respond to stuff too early, ;).
In your case, you are simply going to have to be responsible with internal.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #9

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

Similar topics

5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
2
by: Test User | last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people as possible) I am somewhat familiar with Access 2000, but my latest project has me stumped. So, I defer to you...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
6
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
8
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.